Skip to content

Instantly share code, notes, and snippets.

@elzii
Created November 28, 2016 03:53
Show Gist options
  • Save elzii/bd0f20344aa141aaa71903d2b810e5d7 to your computer and use it in GitHub Desktop.
Save elzii/bd0f20344aa141aaa71903d2b810e5d7 to your computer and use it in GitHub Desktop.
VIM setup Nov 2016
set nocompatible "We want the latest Vim settings/options.
so ~/.vim/plugins.vim
" ---------------------- Basic Settings -----------------------
syntax enable
set backspace=indent,eol,start "Make backspace behave like every other editor.
let mapleader = ',' "The default is \, but a comma is much better.
set number "Let's activate line numbers.
set noerrorbells visualbell t_vb= "No damn bells!
set autowriteall "Automatically write the file when switching buffers.
set complete=.,w,b,u "Set our desired autocompletion matching.
set tabstop=2
"set listchars=tab:▒░,trail:▓
set expandtab
set softtabstop=2
set shiftwidth=2
set ruler
set ttimeout
set ttimeoutlen=50
set laststatus=2
set hidden
set noswapfile
set nowritebackup
set nobackup
set showtabline=2
set magic
" ------------------- Conditional Settings ---------------------
if has('mouse')
set mouse=a
endif
" ---------------------- Visual Settings ----------------------
set t_CO=256
colorscheme atom-dark-256
" set background="dark"
" set guioptions-=l "Disable Gui scrollbars.
" set guioptions-=L
" set guioptions-=r
" set guioptions-=R
" hi vertsplit guifg=bg guibg=bg
"--------------------------- Search -----------------------------
set hlsearch "Highlight all matched terms.
set incsearch "Incrementally highlight, as we type.
"---------------------- Split Management ------------------------
set splitbelow "Make splits default to below...
set splitright "And to the right. This feels more natural.
"-------------------------- Mappings ----------------------------
" Make it easy to edit the Vimrc file.
nmap <Leader>ev :tabedit $MYVIMRC<CR>
nmap <Leader>es :e ~/.vim/snippets/
nmap <Leader>ep :vsplit ~/.vim/plugins.vim<CR>
nmap <Leader>sv :w $MYVIMRC<CR>:source $MYVIMRC<CR>
"badwolf Add simple highlight removal.
nmap <Leader><space> :nohlsearch<CR>
" Quickly browse to any tag/symbol in the project.
"Tip: run ctags -R to regenerated the index.
map <Leader>f :tag<space>
" Sort PHP use statements
" vmap <Leader>su ! awk '{ print length(), $0 \| "sort -n \| cut -d\\ -f2-" }'<cr>
" Turn off hilighting
" map <silent> <Leader><CR> :noh<CR>
map <silent> <Esc><Esc> :noh<CR>
" Close all buffers
map <Leader>ba :bufdo bd<CR>
" nmap <Leader>bd :b#<bar>bd#<CR>
" Smart buffer closing in split
" map <C-q> :bp<bar>sp<bar>bn<bar>bd<CR>
" Tab navigation
map <C-t> :tabedit<CR>
map <C-w> :Bclose<CR>:tabclose<CR>
" Toggle between last accessed tabs
let g:lasttab = 1
nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
au TabLeave * let g:lasttab = tabpagenr()
" Switch CWD to the directory of the open buffer
map <Leader>cd :cd %:p:h<CR>:pwd<CR>
" Use CTRL Up/Down to move line(s)
nmap <C-Down> mz:m+<cr>`z
nmap <C-Up> mz:m-2<cr>`z
vmap <C-Down> :m'>+<cr>`<my`>mzgv`yo`z
vmap <C-Up> :m'<-2<cr>`>my`<mzgv`yo`z
" Indent lines in visual mode
vnoremap <Tab> >
vnoremap <S-Tab> <
" Fix indentation on entire file
map <Leader>ri mzgg=G`z
" Remap visual block mode so we can use CTRL+V like paste
nnoremap V <c-v>
" Use CTRL+Q to close Window
map <Leader>q :wincmd c<CR>
" CMD+ALT Hack
" Use: sed -n l OR cat
" Reference: http://stackoverflow.com/questions/7501092/can-i-map-alt-key-in-vim
" [1;9A -- CMD+ALT+UP
" [1;9B -- CMD+ALT+DOWN
" [1;9C -- CMD+ALT+RIGHT
" [1;9D -- CMD+ALT+LEFT
map <Esc>[1;9C :tabnext<CR>
map <Esc>[1;9D :tabprevious<CR>
" SHIFT+ALT Hack
" Iterm: Enable 'Left Option key acts as (*) Meta'
map <Esc>[1;10A :wincmd k<CR>
map <Esc>[1;10B :wincmd j<CR>
map <Esc>[1;10C :wincmd l<CR>
map <Esc>[1;10D :wincmd h<CR>
" Mimic Shift highlighting behavior
" nmap <S-Up> V
" nmap <S-Down> V
" nmap <S-Left> vb
" nmap <S-Right> ve
" vmap <S-Up> k
" vmap <S-Down> j
" vmap <S-Left> b
" vmap <S-Right> e
" imap <S-Up> <Esc>v<Up>
" imap <S-Down> <Esc>v<Down>
" imap <S-Left> <Esc>v<Left>
" imap <S-Right> <Esc>v<Right>
nmap <S-Up> Vk
nmap <S-Down> Vj
vmap <S-Up> k
vmap <S-Down> j
imap <S-Up> <ESC>Vk
imap <S-Down> <ESC>Vj
" Mimic Cut/Copy/Paste behavior
vmap <C-c> y<Esc>i
vmap <C-x> d<Esc>i
map <C-v> pi
map <C-z> u
imap <C-v> <Esc>pi
imap <C-z> <Esc>ui
imap <C-y> <Esc>Ui
"-------------------------- Plugins ------------------------------
"/
"/ CtrlP
"/
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*
let g:ctrlp_show_hidden = 1
let g:ctrlp_custom_ignore = 'node_modules\DS_Store\|git'
let g:ctrlp_match_window = 'top,order:ttb,min:1,max:30,results:30'
let g:ctrlp_match_func = { 'match': 'pymatcher#PyMatch' }
" nmap <D-p> :CtrlP<cr>
" nmap <D-r> :CtrlPBufTag<cr>
nmap <C-e> :CtrlPMRUFiles<cr>
nmap <C-b> :CtrlPBuffer<cr>
" nmap <D-t> <Plug>PeepOpen
"/
" fzf
"/
" nnoremap <silent> <leader><space> :Files<CR>
" nnoremap <silent> <leader>a :Buffers<CR>
" nnoremap <silent> <leader>A :Windows<CR>
" nnoremap <silent> <leader>; :BLines<CR>
" nnoremap <silent> <leader>o :BTags<CR>
" nnoremap <silent> <leader>O :Tags<CR>
" nnoremap <silent> <leader>? :History<CR>
" " nnoremap <silent> <leader>/ :execute 'Ag ' . input('Ag/')<CR>
" nnoremap <silent> <leader>gl :Commits<CR>
" nnoremap <silent> <leader>ga :BCommits<CR>
" nnoremap <silent> <leader>ft :Filetypes<CR>
"
" imap <C-x><C-f> <plug>(fzf-complete-file-ag)
" imap <C-x><C-l> <plug>(fzf-complete-line)
"
" let g:fzf_action = {
" \ 'ctrl-t': 'tab split',
" \ 'ctrl-x': 'split',
" \ 'ctrl-v': 'vsplit' }
"
" " Default fzf layout
" " - down / up / left / right
" let g:fzf_layout = { 'down': '~40%' }
"
"/
" NERDTree
"/
let NERDTreeHijackNetrw = 0
"/
" greplace
"/
"We want to use Ag for the search.
set grepprg=ag
let g:grep_cmd_opts = '--line-numbers --noheading'
"/
" multiple-cursors
"/
highlight multiple_cursors_cursor term=reverse cterm=reverse gui=reverse
highlight link multiple_cursors_visual Visual
"/
" airline
"/
" let g:airline_theme='badwolf'
" let g:airline_powerline_fonts = 1
" let g:airline#extensions#tabline#enabled = 1
" let g:airline#extensions#tabline#show_buffers = 1
"/
"/ buffergator
"/
map <S-b> :BuffergatorToggle<CR>
"----------------------- Auto-Commands ---------------------------
"Automatically source the Vimrc file on save.
augroup autosourcing
" autocmd BufWritePost .vimrc source %
" autocmd! BufWritePost $MYVIMRC source $MYVIMRC
augroup END
" Return to last edit position when opening files (You want this!)
augroup autolastcursorpos
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
augroup END
"------------------------- Functions ------------------------------
command! Bclose call <SID>BufcloseCloseIt()
function! <SID>BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
if bufnr("%") == l:currentBufNum
new
endif
if buflisted(l:currentBufNum)
execute("bdelete! ".l:currentBufNum)
endif
endfunction
"-------------------------- Tips ---------------------------------
" - Press 'zz' to instantly center the line where the cursor is located.
" - Press 'm<key>' to set a mark
" - Press '`<key>' to get to the mark
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
" Files
" -----------------------------------------------------------
Plugin 'tpope/vim-vinegar'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'FelikZ/ctrlp-py-matcher'
" Plugin 'scrooloose/nerdtree'
" Plugin 'junegunn/fzf'
" Plugin 'junegunn/fzf.vim'
" Search
" -----------------------------------------------------------
Plugin 'skwp/greplace.vim'
Plugin 'rking/ag.vim'
" Version Control
" -----------------------------------------------------------
Plugin 'tpope/vim-fugitive'
" Syntax / Language
" -----------------------------------------------------------
Plugin 'tobyS/vmustache'
" Linting
" -----------------------------------------------------------
Plugin 'ternjs/tern_for_vim'
" Libraries
" -----------------------------------------------------------
Plugin 'tomtom/tlib_vim'
" Utilities
" -----------------------------------------------------------
Plugin 'garbas/vim-snipmate'
Plugin 'tpope/vim-surround'
Plugin 'MarcWeber/vim-addon-mw-utils'
Plugin 'SirVer/ultisnips'
Plugin 'ervandew/supertab'
Plugin 'terryma/vim-multiple-cursors'
Plugin 'tomtom/tcomment_vim'
Plugin 'jiangmiao/auto-pairs'
" Interface
" -----------------------------------------------------------
" Plugin 'vim-airline/vim-airline'
" Plugin 'vim-airline/vim-airline-themes'
" Plugin 'ap/vim-buftabline'
" Plugin 'bling/vim-bufferline'
" Plugin 'critiqjo/vim-bufferline'
Plugin 'itchyny/lightline.vim'
Plugin 'jeetsukumaran/vim-buffergator'
Plugin 'moll/vim-bbye'
" PHP
" -----------------------------------------------------------
" Plugin 'StanAngeloff/php.vim'
" Plugin 'arnaud-lb/vim-php-namespace'
" Plugin 'stephpy/vim-php-cs-fixer'
" Plugin 'tobyS/pdv'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment