" Disable vi-compatibility set nocompatible "=============================================================================== " NeoBundle "=============================================================================== if has ('vim_starting') set runtimepath+=~/.vim/bundle/neobundle.vim/ endif call neobundle#rc(expand('~/.vim/bundle/')) " Let NeoBundle manage NeoBundle NeoBundleFetch 'Shougo/neobundle.vim' NeoBundle 'Shougo/vimproc', { 'build': { \ 'windows': 'make -f make_mingw32.mak', \ 'cygwin': 'make -f make_cygwin.mak', \ 'mac': 'make -f make_mac.mak', \ 'unix': 'make -f make_unix.mak', \ } } " Experiments " NeoBundle 'felixr/vim-multiedit' " NeoBundle 'adinapoli/vim-markmultiple' " NeoBundle 'paradigm/vim-multicursor' " NeoBundle 'AndrewRadev/multichange.vim' " NeoBundle 'daylilyfield/sexyscroll.vim' " NeoBundle 'hlissner/vim-multiedit' " Fuzzy search NeoBundle 'Shougo/unite.vim' NeoBundle 'Shougo/unite-outline' NeoBundle 'Shougo/unite-help' NeoBundle 'Shougo/unite-session' NeoBundle 'thinca/vim-unite-history' NeoBundle 'mileszs/ack.vim' " Code completion " NeoBundle'Shougo/neocomplcache' " NeoBundle 'vim-scripts/AutoComplPop' NeoBundle 'Valloric/YouCompleteMe' " Snippets " NeoBundle 'Shougo/neosnippet' " NeoBundle 'honza/vim-snippets' NeoBundle 'SirVer/ultisnips' " NeoBundle 'JazzCore/neocomplcache-ultisnips' " Marks " NeoBundle 'kshenoy/vim-signature' " Comments NeoBundle 'scrooloose/nerdcommenter' " File browsing NeoBundle 'scrooloose/nerdtree' NeoBundle 'Shougo/vimfiler' " NeoBundle 'fholgado/minibufexpl.vim' " Syntax checker NeoBundle 'scrooloose/syntastic' " Shell NeoBundle 'thinca/vim-quickrun' NeoBundle 'Shougo/vimshell' NeoBundle 'tpope/vim-dispatch' " File types " NeoBundle 'rstacruz/sparkup', {'rtp': 'vim'} "HTML NeoBundle 'tpope/vim-markdown' "Markdown NeoBundle 'terryma/vim-instant-markdown' "Markdown " NeoBundle 'vim-scripts/deb.vim' "Debian packages NeoBundle 'vim-ruby/vim-ruby' "Ruby " Git NeoBundle 'tpope/vim-fugitive' " Motions NeoBundle 'Lokaltog/vim-easymotion' NeoBundle 'goldfeld/vim-seek' " Text Objects NeoBundle 'tpope/vim-surround' NeoBundle 'tpope/vim-repeat' NeoBundle 'kana/vim-textobj-user' NeoBundle 'kana/vim-textobj-entire' " ae, ie NeoBundle 'kana/vim-textobj-lastpat' " a/, i/, a?, i? NeoBundle 'kana/vim-textobj-line' " al, il NeoBundle 'kana/vim-textobj-indent' " ai, ii, aI, iI NeoBundle 'lucapette/vim-textobj-underscore' " a_, i_ " NeoBundle 'terryma/vim-expand-region' " Tags " NeoBundle 'xolox/vim-easytags' NeoBundle 'majutsushi/tagbar' " Status line NeoBundle 'terryma/vim-powerline', {'rev':'develop'} " Color themems NeoBundle 'altercation/vim-colors-solarized' " NeoBundle 'tomasr/molokai' " NeoBundle 'Lokaltog/vim-distinguished' " NeoBundle 'chriskempson/base16-vim' " NeoBundle 'tpope/vim-vividchalk' " NeoBundle 'chriskempson/tomorrow-theme', {'rtp': 'vim'} " NeoBundle 'rainux/vim-desert-warm-256' NeoBundle 'nanotech/jellybeans.vim' " NeoBundle 'vim-scripts/wombat256.vim' " Misc NeoBundle 'kana/vim-submode' NeoBundle 'kana/vim-scratch' NeoBundle 'vim-scripts/BufOnly.vim' NeoBundle 'sjl/gundo.vim' NeoBundle 't9md/vim-quickhl' NeoBundle 'mattn/webapi-vim' NeoBundle 'mattn/gist-vim' NeoBundle 'koron/nyancat-vim' NeoBundle 'Raimondi/delimitMate' " NeoBundle 'terryma/vim-smooth-scroll' " Ones that I don't really use anymore " NeoBundle 'vim-scripts/TaskList.vim' " NeoBundle 'myusuf3/numbers.vim' " NeoBundle 'kana/vim-arpeggio' " NeoBundle 'kana/vim-smartinput' " NeoBundle 'Shougo/echodoc' " NeoBundle 'klen/python-mode' " NeoBundle 'nathanaelkane/vim-indent-guides' " NeoBundle 'hynek/vim-python-pep8-indent' " NeoBundle 'kien/ctrlp.vim' " NeoBundle 'mattn/calendar-vim' " NeoBundle 'sjl/clam.vim' " NeoBundle 'xolox/vim-session' " NeoBundle 'sjl/vitality.vim' " Load local plugins, nice for doing development execute 'NeoBundleLocal' '~/code/vim' filetype plugin indent on syntax enable NeoBundleCheck "=============================================================================== " Experiments "=============================================================================== " add currently selected region to multiedit " map ,,a (multiedit-add) " add a space and mark it as multiedit region " map ,,s Iv(multiedit-add) " mark word as multiedit region " map ,,w viw(multiedit-add)b " start editing multiedit regions " map ,,i (multiedit-edit)i " reset/clear multiedit regions " map ,,q (multiedit-reset) " let g:multicursor_quit = "" "=============================================================================== " Local Settings "=============================================================================== try source ~/.vimrc.local catch endtry "=============================================================================== " General Settings "=============================================================================== " Set augroup augroup MyAutoCmd autocmd! augroup END syntax on " This took a while to figure out. Neocomplcache + iTerm + the CursorShape " fix is causing the completion menu popup to flash the first result. Tested it " with AutoComplPop and the behavior doesn't exist, so it's isolated to " Neocomplcache... :( Dug into the source for both and saw that AutoComplPop is " setting lazyredraw to be on during automatic popup... set lazyredraw " Solid line for vsplit separator set fcs=vert:│ " Turn on the mouse, since it doesn't play well with tmux anyway. This way I can " scroll in the terminal set mouse=a " Give one virtual space at end of line set virtualedit=onemore " Turn on line number set number " Always splits to the right and below set splitright set splitbelow " 256bit terminal set t_Co=256 " Colorscheme colorscheme jellybeans " Tell Vim to use dark background set background=dark " Sets how many lines of history vim has to remember set history=10000 " Set to auto read when a file is changed from the outside set autoread " Set to auto write file set autowriteall " Display unprintable chars set list set listchars=tab:▸\ ,extends:❯,precedes:❮,nbsp:␣ set showbreak=↪ " listchar=trail is not as flexible, use the below to highlight trailing " whitespace. Don't do it for unite windows or readonly files highlight ExtraWhitespace ctermbg=red guibg=red match ExtraWhitespace /\s\+$/ augroup MyAutoCmd autocmd BufWinEnter * if &modifiable && &ft!='unite' | match ExtraWhitespace /\s\+$/ | endif autocmd InsertEnter * if &modifiable && &ft!='unite' | match ExtraWhitespace /\s\+\%#\@A .. z if !has('gui_running') " let c='a' " while c <= 'z' " exec "set =\e".c " exec "imap \e".c." " " let c = nr2char(1+char2nr(c)) " endw " Map these two on its own to enable Alt-Shift-J and Alt-Shift-K. If I map the " whole spectrum of A-Z, it screws up mouse scrolling somehow. Mouse events " must be interpreted as some form of escape sequence that interferes. " exec 'set =J' " exec 'set =K' endif " Reload vimrc when edited, also reload the powerline color autocmd MyAutoCmd BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc \ so $MYVIMRC | call Pl#Load() | if has('gui_running') | so $MYGVIMRC | endif try lang en_us catch endtry " Turn backup off set nobackup set nowritebackup set noswapfile " Tab settings set expandtab set shiftwidth=2 set tabstop=8 set softtabstop=2 set smarttab " Text display settings set linebreak set textwidth=80 set autoindent set nowrap set whichwrap+=h,l,<,>,[,] " Writes to the unnamed register also writes to the * and + registers. This " makes it easy to interact with the system clipboard if has ('unnamedplus') set clipboard=unnamedplus else set clipboard=unnamed endif " Spelling highlights. Use underline in term to prevent cursorline highlights " from interfering if !has("gui_running") hi clear SpellBad hi SpellBad cterm=underline ctermfg=red hi clear SpellCap hi SpellCap cterm=underline ctermfg=blue hi clear SpellLocal hi SpellLocal cterm=underline ctermfg=blue hi clear SpellRare hi SpellRare cterm=underline ctermfg=blue endif " Use a low updatetime. This is used by CursorHold set updatetime=1000 " I like my word boundary to be a little bigger than the default set iskeyword+=<,>,[,],:,-,`,! set iskeyword-=_ " Cursor settings. This makes terminal vim sooo much nicer! " Tmux will only forward escape sequences to the terminal if surrounded by a DCS " sequence if exists('$TMUX') let &t_SI = "\Ptmux;\\]50;CursorShape=1\x7\\\" let &t_EI = "\Ptmux;\\]50;CursorShape=0\x7\\\" else let &t_SI = "\]50;CursorShape=1\x7" let &t_EI = "\]50;CursorShape=0\x7" endif "=============================================================================== " Function Key Mappings "=============================================================================== " : Help nmap [unite]h " : Open Vimfiler " : Gundo nnoremap :GundoToggle " : Save session nnoremap :UniteSessionSave "=============================================================================== " Leader Key Mappings "=============================================================================== " Map leader and localleader key to comma let mapleader = "," let g:mapleader = "," let maplocalleader = "," let g:maplocalleader = "," " ``: Force quit all nnoremap `` :qa! " 1: Toggle between paste mode nnoremap 1 :set paste! " 2: Toggle Tagbar nnoremap 2 :TagbarToggle " 0: Run the visually selected code in python and replace it with the " output vnoremap 0 :!python " tab: Toggles NERDTree nnoremap :NERDTreeToggle " q: Quit all, very useful in vimdiff nnoremap q :qa " w: Save all nnoremap w :wa " e: Fast editing of the .vimrc nnoremap e :e! ~/.dotfiles/.vimrc " r: QuickRun's default keymap " t: TODO " TODO y " TODO u " o: only nnoremap o :only " p: Copy the full path of the current file to the clipboard nnoremap p :let @+=expand("%:p"):echo "Copied current file \ path '".expand("%:p")."' to clipboard" " a: TODO " s: Spell checking shortcuts nnoremap ss :setlocal spell! nnoremap sj ]s nnoremap sk [s nnoremap sa zg]s nnoremap sd 1z= nnoremap sf z= " d: Delete the current buffer nnoremap d :bdelete " f: Open Quickfix nnoremap f :botright copen " g: Fugitive shortcuts " z: TODO " x: TODO " c*: NERDCommenter mappings " cd: Switch to the directory of the open buffer nnoremap cd :cd %:p:h:pwd " v: TODO " b: TODO " n: NERDTreeFind nnoremap n :NERDTreeFind :wincmd p " m: Maximize current split nnoremap m _ " : TODO " ,: Switch to previous split nnoremap , p "=============================================================================== " Command-line Mode Key Mappings "=============================================================================== " Bash like keys for the command line. These resemble personal zsh mappings cnoremap cnoremap " Ctrl-[hl]: Move left/right by word cnoremap cnoremap " Ctrl-Space: Show history cnoremap cnoremap cnoremap cnoremap cnoremap " Ctrl-Delete: Delete previous word. HACK ALERT! Ctrl-Delete sends d in iTerm2 cnoremap " Ctrl-v: Paste cnoremap " " w!: Change ro files to rw " function! s:chmodonwrite() " if v:cmdbang " silent !chmod u+w % " endif " endfunction " autocmd MyAutoCmd bufwrite * call s:chmodonwrite() " w!!: Writes using sudo cnoremap w!! w !sudo tee % >/dev/null "=============================================================================== " Normal Mode Shift Key Mappings "=============================================================================== " Shift-Tab: NERDTree nnoremap :NERDTreeToggle " Q: Closes the window nnoremap Q :q " W: Move word forward (TODO Replaced by , maybe remap?) " E: Move to end of word forward " R: Replace mode (When do I ever use this?) " T: Finds till backwards " Y: Remove join lines to this, Y looks like a join of two lines into one noremap Y J " U: Redos since 'u' undos nnoremap U " I: Insert at beginning of line " O: Insert line above " P: Paste above line " {: Beginning of paragraph " }: End of paragraph " _ : Quick horizontal splits nnoremap _ :sp " | : Quick vertical splits nnoremap :vsp " A: Insert at end of line " S: Vim-seek backward " D: Deletes til the end of line " F: Finds backwards " G: Go to end of file " H: Go to beginning of line. Repeated invocation goes to previous line noremap H getpos('.')[2] == 1 ? 'k' : '^' " J: expand-region map K (expand_region_expand) " K: shrink-region map J (expand_region_shrink) " L: Go to end of line. Repeated invocation goes to next line noremap L end_of_line() function! s:end_of_line() let l = len(getline('.')) if (l == 0 || l == getpos('.')[2]-1) return 'jg_' else return 'g_' endfunction " :: Remap to ,. After all the remapping, ; goes to command mode, . repeats " fFtT, : repeats it backward, and , is the leader noremap : , " ": Handles registers " Z: TODO " X: Deletes character backward (When was the last time I actually used this?) " C: Deletes rest of line and go to insert mode " V: Visual line mode " B: Move word backward (TODO Replaced by , maybe remap?) " N: Find next occurrence backward nnoremap N Nzzzv " M: Move cursor to mid screen (When was the last time I actually used this?) " <: Indent left " >: Indent right " ?: Search backwards " +/-: Increment number nnoremap + nnoremap - "=============================================================================== " Normal Mode Ctrl Key Mappings "=============================================================================== " Ctrl-q: Visual block mode " Ctrl-w: Window management " Ctrl-e: Ended up using L. Remap TODO noremap $ " Ctrl-r: Command history using Unite, this matches my muscle memory in zsh nmap [unite]; " Ctrl-t: Go back in tag stack " Ctrl-t*: Tab operations (When was the last time I used tabs?) nnoremap :tabnew nnoremap :tabclose nnoremap :tabprev nnoremap :tabprev nnoremap :tabnext nnoremap :tabnext let g:lasttab = 1 nnoremap :exe "tabn ".g:lasttab autocmd MyAutoCmd TabLeave * let g:lasttab = tabpagenr() " Ctrl-y: Yanks nmap [unite]y " Ctrl-u: Scroll half a screen up smoothly noremap :call smooth_scroll#up(&scroll, 0, 3) " Ctrl-i: Go forward in the jumplist, also realigns screen. See mapping for " " Ctrl-o: Go back in the jumplist, also realign the screen " nnoremap zzzv " Ctrl-p: Previous cursor in MultiCursor mode " Ctrl-[: Esc " Ctrl-]: Go forward in tag stack " Ctrl-\: Quick outline nmap [unite]o " Ctrl-a: TODO " Ctrl-sa: (S)elect (a)ll nnoremap :keepjumps normal ggVG " Ctrl-ss: (S)earch word under cur(s)or in current directory nnoremap :Unite grep:.:: " Ctrl-sd: (S)earch word in current (d)irectory (prompt for word) nnoremap :Unite grep:. " Ctrl-sf: Quickly (s)earch in (f)ile nmap [unite]l " Ctrl-sr: Easier (s)earch and (r)eplace nnoremap :%s///gc " Ctrl-sw: Quickly surround word nmap ysiw " Ctrl-d: Scroll half a screen down smoothly noremap :call smooth_scroll#down(&scroll, 0, 3) " Ctrl-fm: (F)ind (M)RU and buffers nmap [unite]u " Ctrl-fa: (F)ind (A)all files recursively nmap [unite]f " Ctrl-fd: (F)ind (d)irectory. Change directory nmap [unite]d " Ctrl-ff: EasyMotion " Ctrl-ft: EasyMotion " Ctrl-g: Prints current file name nnoremap 1 " Ctrl-h: Move word back. Consistent with zsh noremap b " Ctrl-j: Scroll + move down through the file noremap 33j " Ctrl-k: Scroll + move up through the file noremap 33k " Ctrl-l: Move word forward. Consistent with zsh noremap w " Ctrl-;: Vim can't map this " Ctrl-': Vim can't map this " Ctrl-z: This is the command key for tmux " Ctrl-x: Skip curosr in MultiCursor mode " Ctrl-c: (C)ycle through the splits. I don't ever use enough splits to justify " wasting 4 very easy to hit keys for them. nnoremap w " Ctrl-v: Paste (works with system clipboard due to clipboard setting earlier) nnoremap p " Ctrl-b: Go (b)ack. Go to previously buffer nnoremap " Ctrl-n: Next cursor in MultiCursor mode " Ctrl-m: Same as Enter " Ctrl-,: Vim can't map this " Ctrl-.: Vim can't map this " Ctrl-/: A more powerful '/' nmap [unite]l " Ctrl-Space: Quick scratch buffer nmap (scratch-open) nmap "=============================================================================== " Insert Mode Ctrl Key Mappings "=============================================================================== " Ctrl-q: Quoted insert. Useful for doing key binding " Ctrl-w: Delete previous word, create undo point inoremap u " Ctrl-e: Go to end of line inoremap A " Ctrl-r: Insert register " Ctrl-t: Indent shiftwidth " Ctrl-y: Insert char above cursor " TODO: When do I ever use this? " Ctrl-u: Delete til beginning of line, create undo point inoremap u " Ctrl-i: Tab " Ctrl-o: Execute one normal mode command " Ctrl-p: Auto complete previous " TODO: When do I ever use this? " Ctrl-a: Go to begin of line inoremap I " Ctrl-s: Save inoremap :w " Ctrl-d: Unindent shiftwidth " Ctrl-f: Move cursor left inoremap " Ctrl-g: Move cursor right " Surround.vim maps these things that I don't use silent! iunmap s silent! iunmap S inoremap " Ctrl-h: Move word left inoremap b " Ctrl-j: Move cursor up inoremap pumvisible() ? "\\" : "\" " Ctrl-k: Move cursor up inoremap pumvisible() ? "\\" : "\" " Ctrl-l: Move word right inoremap w " Ctrl-z: This is the command key for tmux " Ctrl-x: Delete char under cursor. (If we simply use x, it wouldn't delete " newline chars " inoremap X " Ctrl-c: Inserts line below inoremap o " Ctrl-v: Paste. For some reason, is not creating an undo point in the " mapping inoremap ugP " Ctrl-b: TODO " Ctrl-n: Auto complete next " Ctrl-m: Same as Enter " Ctrl-space: TODO " Ctrl-/: Undo inoremap u "=============================================================================== " Visual Mode Ctrl Key Mappings "=============================================================================== " Ctrl-c: Copy (works with system clipboard due to clipboard setting) vnoremap y`] " Ctrl-r: Easier search and replace vnoremap "hy:%s/h//gc " Ctrl-s: Easier substitue vnoremap :s/\%V//g "=============================================================================== " Normal Mode Meta Key Mappings "=============================================================================== " Alt-a: Select all nnoremap ggVG nnoremap a ggVG " Alt-s: Go back in changelist. HACK ALERT! Ctrl-i generates s with iTerm2 nnoremap zzzv nnoremap s " Alt-d: Delete previous word. HACK ALERT! Ctrl-Delete generates d with " iTerm2 nnoremap db nnoremap d db " Alt-h: Go to previous tmux window " Alt-j: Move current line up nnoremap mz:m+`z== " Alt-k: Move current line down nnoremap mz:m-2`z== " Alt-l: Go to next tmux window " Alt-Shift-j: Duplicate line down nnoremap mzyyp`zj " Alt-Shift-k: Duplicate line up nnoremap mzyyp`z " Alt-o: Jump back in the changelist nnoremap g; " Alt-i: Jump forward in the changelist nnoremap g, " Alt-n: Open new tmux window "=============================================================================== " Insert Mode Meta Key Mappings "=============================================================================== " Alt-d: Delete previous word. HACK ALERT! Ctrl-Delete sends d in iTerm2 inoremap u inoremap d u " Alt-j: Move current line up imap a " Alt-k: Move current line down imap a "=============================================================================== " Visual Mode Meta Key Mappings "=============================================================================== " Alt-j: Move selections up vnoremap :m'>+`mzgv`yo`z " Alt-k: Move selections down vnoremap :m'<-2`>my`j', '3') " call submode#enter_with('scroll', 'n', '', 'k', '3') " call submode#map('scroll', 'n', '', 'j', '3') " call submode#map('scroll', 'n', '', 'k', '3') call submode#enter_with('scroll', 'n', '', 'j', ':call smooth_scroll#down(&scroll/2, 0, 1)') call submode#enter_with('scroll', 'n', '', 'k', ':call smooth_scroll#up(&scroll/2, 0, 1)') call submode#map('scroll', 'n', '', 'j', ':call smooth_scroll#down(&scroll/2, 0, 1)') call submode#map('scroll', 'n', '', 'k', ':call smooth_scroll#up(&scroll/2, 0, 1)') " Don't leave submode automatically let g:submode_timeout = 0 " Space-=: Resize windows nnoremap = = " Space-m: quickhl " nmap m (quickhl-toggle) " xmap m (quickhl-toggle) " nmap M (quickhl-reset) " xmap M (quickhl-reset) " Space-t: ScratchBuffer (temp) nmap t (scratch-open) "=============================================================================== " Arpeggio Mappings "=============================================================================== " call arpeggio#load() " Arpeggioimap fj "=============================================================================== " Normal Mode Key Mappings "=============================================================================== " q: Record macros " w: Move word forward " e: Move to end of word " r: Replace single character " t: Find till " y: Yank " u: Undo " i: Insert before cursor " o: Insert line below cursor " p: Paste nnoremap p gp " [: Many functions " ]: Many functions " \: Toggle comment nmap \ c " a: Insert after cursor " s: Substitute " d: Delete into the blackhole register to not clobber the last yank nnoremap d "_d " dd: I use this often to yank a single line, retain its original behavior nnoremap dd dd " f: Find. Also support repeating with . nnoremap OriginalSemicolon ; nnoremap f :call repeat#set("\Plug>OriginalSemicolon")f nnoremap t :call repeat#set("\Plug>OriginalSemicolon")t nnoremap F :call repeat#set("\Plug>OriginalSemicolon")F nnoremap T :call repeat#set("\Plug>OriginalSemicolon")T " g: Many functions " gp to visually select pasted text nnoremap gp '`[' . strpart(getregtype(), 0, 1) . '`]' " h: Left " j: Down " k: Up " l: Right " ;: Command mode noremap ; : " ': Go to mark " z: Many functions " x: Delete char " c: Change into the blackhole register to not clobber the last yank nnoremap c "_c " v: Visual mode " b: Move word backward " n: Next, keep search matches in the middle of the window nnoremap n nzzzv " m: Marks " ,: Leader " .: Repeat last command " /" Search " Up Down Left Right resize splits nnoremap + nnoremap - nnoremap < nnoremap > " Enter: Toggle search highlight nnoremap :set hlsearch! hlsearch? " Backspace: Act like normal backspace nnoremap X " Tab: Go to matching element nnoremap % "=============================================================================== " Visual Mode Key Mappings "=============================================================================== " y: Yank and go to end of selection xnoremap y y`] " p: Paste in visual mode should not replace the default register with the " deleted text xnoremap p "_dP " d: Delete into the blackhole register to not clobber the last yank. To 'cut', " use 'x' instead xnoremap d "_d " \: Toggle comment xmap \ c " Enter: Highlight visual selections xnoremap y:let @/ = @":set hlsearch " Backspace: Delete selected and go into insert mode xnoremap c " Space: QuickRun xnoremap :QuickRun " <|>: Reselect visual block after indent xnoremap < >gv " .: repeats the last command on every line xnoremap . :normal. " @: repeats macro on every line xnoremap @ :normal@ " Tab: Indent xmap > " shift-tab: unindent xmap < "=============================================================================== " Operator Pending Mode Key Mappings "=============================================================================== "=============================================================================== " Autocommands "=============================================================================== " Turn on cursorline only on active window augroup MyAutoCmd autocmd WinLeave * setlocal nocursorline autocmd WinEnter,BufRead * setlocal cursorline augroup END " q quits in certain page types. Don't map esc, that interferes with mouse input autocmd MyAutoCmd FileType help,quickrun \ if (!&modifiable || &ft==#'quickrun') | \ nnoremap q :q| \ nnoremap :q| \ endif autocmd MyAutoCmd FileType qf nnoremap q :q " json = javascript syntax highlight autocmd MyAutoCmd FileType json setlocal syntax=javascript " Enable omni completion augroup MyAutoCmd autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS autocmd FileType python setlocal omnifunc=pythoncomplete#Complete autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags autocmd FileType ruby setlocal omnifunc=rubycomplete#Complete autocmd FileType java setlocal omnifunc=eclim#java#complete#CodeComplete augroup END " Diff mode settings " au MyAutoCmd FilterWritePre * if &diff | exe 'nnoremap [c' | exe 'nnoremap ]c' | endif "=============================================================================== " NERDTree "=============================================================================== let NERDTreeShowBookmarks=1 let NERDTreeShowHidden=1 let NERDTreeIgnore=['\~$', '\.swp$', '\.git', '\.hg', '\.svn', '\.bzr'] " Close vim if the only window open is nerdtree autocmd MyAutoCmd BufEnter * \ if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif "=============================================================================== " NERDCommenter "=============================================================================== " Always leave a space between the comment character and the comment let NERDSpaceDelims=1 "=============================================================================== " Powerline "=============================================================================== " Use the fancy version of Powerline symbols let g:Powerline_symbols = 'fancy' "=============================================================================== " Syntastic "=============================================================================== " TODO(terryma): Update these settings " Syntastic settings let g:syntastic_mode_map = { 'mode': 'active', \ 'active_filetypes': ['ruby', 'php'], \ 'passive_filetypes': ['puppet'] } "=============================================================================== " Fugitive "=============================================================================== nnoremap gb :Gblame nnoremap gc :Gcommit nnoremap gd :Gdiff nnoremap gp :Git push nnoremap gr :Gremove nnoremap gs :Gstatus nnoremap gw :Gwrite " Quickly stage, commit, and push the current file. Useful for editing .vimrc nnoremap gg :Gwrite:Gcommit -m 'update':Git push "=============================================================================== " EasyMotion "=============================================================================== " Tweak the colors hi link EasyMotionTarget WarningMsg hi link EasyMotionShade Comment let g:EasyMotion_do_mapping = 0 nnoremap f :call EasyMotion#F(0, 0) nnoremap :call EasyMotion#F(0, 1) nnoremap t :call EasyMotion#T(0, 0) nnoremap :call EasyMotion#T(0, 1) "=============================================================================== " Neocomplcache and Neosnippets "=============================================================================== " Launches neocomplcache automatically on vim startup. " let g:neocomplcache_enable_at_startup = 0 " Use smartcase. " let g:neocomplcache_enable_smart_case = 1 " Use camel case completion. " let g:neocomplcache_enable_camel_case_completion = 1 " Use underscore completion. " let g:neocomplcache_enable_underbar_completion = 1 " Sets minimum char length of syntax keyword. " let g:neocomplcache_min_syntax_length = 4 " let g:neocomplcache_min_keyword_length = 4 " AutoComplPop like behavior. " let g:neocomplcache_enable_auto_select = 1 " let g:snips_author = "Terry Ma" " let g:neocomplcache_max_list=10 " 's function is overloaded depending on the context: " - If the current word is a snippet, then expand that snippet " - If we're in the middle of a snippet, tab jumps to the next placeholder text " - If the competion menu is visible, enter the currently selected entry and " close the popup " - If none of the above is true, simply do what does originally " imap neosnippet#expandable_or_jumpable() ? "\(neosnippet_expand_or_jump)" : pumvisible() ? neocomplcache#close_popup() : "\" " smap neosnippet#expandable_or_jumpable() ? "\(neosnippet_expand_or_jump)" : "\" " Enter always performs a literal enter " imap neocomplcache#smart_close_popup() . "\" " if has('conceal') " set conceallevel=2 concealcursor=i " endif " Tell Neosnippets to use the snipmate snippets " let g:neosnippet#snippets_directory='~/.dotfiles/.vim/bundle/snipmate-snippets,~/.dotfiles/.vim/snippets' " These are the battle scars of me trying to get omni_patterns to work correctly " so Neocomplcache and Eclim could co-exist peacefully. No cigar. " if !exists('g:neocomplcache_force_omni_patterns') " let g:neocomplcache_force_omni_patterns = {} " endif " if !exists('g:neocomplcache_omni_patterns') " let g:neocomplcache_omni_patterns = {} " endif " let g:neocomplcache_force_omni_patterns.java = '\%(\.\)\h\w*' " let g:neocomplcache_force_omni_patterns.java = '.' " let g:neocomplcache_omni_patterns.java = '\%(\.\)\h\w*' " Ok this requires some explanation. I couldn't get Neocomplcache and Eclim to " play nice with each other. When Neocomplcache triggers omni_complete under " Eclim, everything just blows up. I tried to configure omni_patterns using " Neocomplcache, but nothing I tried worked. What eventually worked is disabling " omni_complete from the Neocomplcache sources for java files, and trigger it " manually with Ctrl-Space. Neocomplcache also has this strange behavior where " it overrides the completeopt flag to always remove 'longest'. In order for " Ctrl-Space to trigger sane behavior of autocomplete and not always select the " first entry by default, I need to temporarily set completeopt to include " longest when the key is triggered. Theoratically I could call " neocomplcache#start_manual_complete, but I think that requires the " omni_patterns to set correctly and I couldn't get that to work " function! s:disable_neocomplcache_for_java() " if &ft ==# 'java' " :NeoComplCacheLockSource omni_complete " inoremap =java_omni_complete() " endif " endfunction " function! s:java_omni_complete() " setlocal completeopt+=longest " return "\\" " endfunction " autocmd MyAutoCmd BufEnter * call s:disable_neocomplcache_for_java() "=============================================================================== " Unite "=============================================================================== " Use the fuzzy matcher for everything call unite#filters#matcher_default#use(['matcher_fuzzy']) " Use the rank sorter for everything call unite#filters#sorter_default#use(['sorter_rank']) " Set up some custom ignores call unite#custom_source('file_rec,file_rec/async,file_mru,file,buffer,grep', \ 'ignore_pattern', join([ \ '\.git/', \ 'git5/.*/review/', \ 'google/obj/', \ ], '\|')) " Map space to the prefix for Unite nnoremap [unite] nmap [unite] " General fuzzy search nnoremap [unite] :Unite \ -buffer-name=files buffer file_mru bookmark file_rec/async " Quick registers nnoremap [unite]r :Unite -buffer-name=register register " Quick buffer and mru nnoremap [unite]u :Unite -buffer-name=buffers buffer file_mru " Quick yank history nnoremap [unite]y :Unite -buffer-name=yanks history/yank " Quick outline nnoremap [unite]o :Unite -buffer-name=outline -vertical outline " Quick sessions (projects) nnoremap [unite]p :Unite -buffer-name=sessions session " Quick sources nnoremap [unite]a :Unite -buffer-name=sources source " Quick snippet nnoremap [unite]s :Unite -buffer-name=snippets snippet " Quickly switch lcd nnoremap [unite]d \ :Unite -buffer-name=change-cwd -default-action=lcd directory_mru " Quick file search nnoremap [unite]f :Unite -buffer-name=files file_rec/async file/new " Quick grep from cwd nnoremap [unite]g :Unite -buffer-name=grep grep:. " Quick help nnoremap [unite]h :Unite -buffer-name=help help " Quick line using the word under cursor nnoremap [unite]l :UniteWithCursorWord -buffer-name=search_file line " Quick MRU search nnoremap [unite]m :Unite -buffer-name=mru file_mru " Quick find nnoremap [unite]n :Unite -buffer-name=find find:. " Quick commands nnoremap [unite]c :Unite -buffer-name=commands command " Quick bookmarks nnoremap [unite]b :Unite -buffer-name=bookmarks bookmark " Fuzzy search from current buffer " nnoremap [unite]b :UniteWithBufferDir " \ -buffer-name=files -prompt=%\ buffer file_mru bookmark file " Quick commands nnoremap [unite]; :Unite -buffer-name=history history/command command " Custom Unite settings autocmd MyAutoCmd FileType unite call s:unite_settings() function! s:unite_settings() nmap (unite_exit) imap (unite_exit) " imap (unite_select_next_line) imap (unite_insert_leave) nmap (unite_loop_cursor_down) nmap (unite_loop_cursor_up) imap (unite_choose_action) imap (unite_exit_insert) imap jj (unite_insert_leave) imap (unite_delete_backward_word) imap (unite_delete_backward_path) imap ' (unite_quick_match_default_action) nmap ' (unite_quick_match_default_action) nmap (unite_redraw) imap (unite_redraw) inoremap unite#do_action('split') nnoremap unite#do_action('split') inoremap unite#do_action('vsplit') nnoremap unite#do_action('vsplit') let unite = unite#get_current_unite() if unite.buffer_name =~# '^search' nnoremap r unite#do_action('replace') else nnoremap r unite#do_action('rename') endif nnoremap cd unite#do_action('lcd') " Using Ctrl-\ to trigger outline, so close it using the same keystroke if unite.buffer_name =~# '^outline' imap (unite_exit) endif " Using Ctrl-/ to trigger line, close it using same keystroke if unite.buffer_name =~# '^search_file' imap (unite_exit) endif endfunction " Start in insert mode let g:unite_enable_start_insert = 1 " Enable short source name in window " let g:unite_enable_short_source_names = 1 " Enable history yank source let g:unite_source_history_yank_enable = 1 " Open in bottom right let g:unite_split_rule = "botright" " Shorten the default update date of 500ms let g:unite_update_time = 200 let g:unite_source_file_mru_limit = 1000 let g:unite_cursor_line_highlight = 'TabLineSel' " let g:unite_abbr_highlight = 'TabLine' let g:unite_source_file_mru_filename_format = ':~:.' let g:unite_source_file_mru_time_format = '' " For ack. if executable('ack-grep') let g:unite_source_grep_command = 'ack-grep' " Match whole word only. This might/might not be a good idea let g:unite_source_grep_default_opts = '--no-heading --no-color -a -w' let g:unite_source_grep_recursive_opt = '' elseif executable('ack') let g:unite_source_grep_command = 'ack' let g:unite_source_grep_default_opts = '--no-heading --no-color -a -w' let g:unite_source_grep_recursive_opt = '' endif "=============================================================================== " Unite Sessions "=============================================================================== " Save session automatically. let g:unite_source_session_enable_auto_save = 1 " Pop up session selection if no file is specified " TODO: Why does this not work when Vim isn't run from tmux???! autocmd MyAutoCmd VimEnter * call s:unite_session_on_enter() function! s:unite_session_on_enter() if !argc() && !exists("g:start_session_from_cmdline") Unite -buffer-name=sessions session endif endfunction "=============================================================================== " Vimfiler "=============================================================================== " TODO Look into Vimfiler more " Example at: https://github.com/hrsh7th/dotfiles/blob/master/vim/.vimrc nnoremap g:my_open_explorer_command() function! g:my_open_explorer_command() return printf(":\VimFilerBufferDir -buffer-name=%s -split -auto-cd -toggle -no-quit -winwidth=%s\", \ g:my_vimfiler_explorer_name, \ g:my_vimfiler_winwidth) endfunction let g:vimfiler_as_default_explorer = 1 let g:vimfiler_tree_leaf_icon = ' ' let g:vimfiler_tree_opened_icon = '▾' let g:vimfiler_tree_closed_icon = '▸' " let g:vimfiler_file_icon = ' ' let g:vimfiler_marked_file_icon = '✓' " let g:vimfiler_readonly_file_icon = ' ' let g:my_vimfiler_explorer_name = 'explorer' let g:my_vimfiler_winwidth = 30 let g:vimfiler_safe_mode_by_default = 0 " let g:vimfiler_directory_display_top = 1 autocmd MyAutoCmd FileType vimfiler call s:vimfiler_settings() function! s:vimfiler_settings() nmap vimfiler#smart_cursor_map("\(vimfiler_expand_tree)", "e") endfunction "=============================================================================== " VimShell "=============================================================================== let g:vimshell_prompt = "% " let g:vimshell_user_prompt = 'fnamemodify(getcwd(), ":~")' autocmd MyAutoCmd FileType vimshell call s:vimshell_settings() function! s:vimshell_settings() call vimshell#altercmd#define('g', 'git') endfunction "=============================================================================== " QuickRun "=============================================================================== let g:quickrun_config = {} let g:quickrun_config['*'] = { \ 'runner/vimproc/updatetime' : 100, \ 'outputter' : 'buffer', \ 'runner' : 'vimproc', \ 'running_mark' : 'バン(∩`・ω・)バンバンバンバン゙ン', \ 'into' : 1, \ 'runmode' : 'async:remote:vimproc' \} " QuickRun triggers markdown preview let g:quickrun_config.markdown = { \ 'runner': 'vimscript', \ 'command': ':InstantMarkdownPreview', \ 'exec': '%C', \ 'outputter': 'null' \} "=============================================================================== " ScratchBuffer "=============================================================================== autocmd MyAutoCmd User PluginScratchInitializeAfter \ call s:on_User_plugin_scratch_initialize_after() function! s:on_User_plugin_scratch_initialize_after() map (scratch-evaluate!) endfunction let g:scratch_show_command = 'hide buffer' "=============================================================================== " Quickhl "=============================================================================== let g:quickhl_colors = [ \ "gui=bold ctermfg=255 ctermbg=153 guifg=#ffffff guibg=#0a7383", \ "gui=bold guibg=#a07040 guifg=#ffffff", \ "gui=bold guibg=#4070a0 guifg=#ffffff", \ ] "=============================================================================== " Instant Markdown "=============================================================================== " let g:instant_markdown_slow = 1 let g:instant_markdown_autostart = 0 "=============================================================================== " Markdown "=============================================================================== " These are ammended on top of the existing markdown settings from " tpope/vim-markdown autocmd MyAutoCmd FileType markdown call s:markdown_settings() function! s:markdown_settings() " Auto insert bullet when constructing lists setlocal comments=b:- setlocal formatoptions+=ro setlocal wrap setlocal tw=0 inoremap " Since completion is off, reassign tab and shift-tab to indent and unindent " in insert mode inoremap " Make the delete key in insert mode delete the bullet point in 1 keystroke inoremap =markdown_delete_key() endfunction function! s:markdown_delete_key() if getline(".") =~ '^\s*- $' return "\\" else return "\" endif endfunction " Turn off completion, it's more disruptive than helpful function! s:markdown_disable_autocomplete() if &ft ==# 'markdown' " :NeoComplCacheLock endif endfunction autocmd MyAutoCmd BufEnter * call s:markdown_disable_autocomplete() "=============================================================================== " Minibufexplorer "=============================================================================== " Conflicts with C-w,p " let g:miniBufExplVSplit=30 " let g:miniBufExplShowBufNumbers=0 " let g:miniBufExplCheckDupeBufs = 0 " let g:miniBufExplMapCTabSwitchBufs = 1 " let g:miniBufExplorerMoreThanOne=4 " This prevents the explorer to open for vimdiff "=============================================================================== " Expand Region "=============================================================================== " This option currently isn't working :( Neosnippet is unmappion my " select mode mappings, so if I switch buffer and come back, the mappings no " longer work. Not sure how to solve that " let g:expand_region_use_select_mode = 1 let g:expand_region_use_select_mode = 0 " Extend the global dictionary call expand_region#custom_text_objects({ \ 'a]' :1, \ 'ab' :1, \ 'aB' :1, \ 'ii' :0, \ 'ai' :0, \ }) " Customize it further for ruby call expand_region#custom_text_objects('ruby', { \ 'im' :0, \ 'am' :0, \ }) "=============================================================================== " DelimitMate "=============================================================================== autocmd MyAutoCmd FileType vim let b:delimitMate_quotes = "'" "=============================================================================== " YCM "=============================================================================== let g:ycm_confirm_extra_conf = 0 "=============================================================================== " My functions "=============================================================================== " function! Refactor() " call inputsave() " let @z=input("What do you want to rename '" . @z . "' to? ") " call inputrestore() " endfunction " " Locally (local to block) rename a variable " nnoremap rf "zyiw:call Refactor()mx:silent! norm gd[{V%:s///z/g`x command! -nargs=+ Silent \ | execute ':silent !'. \ | execute ':redraw!' " Format json using python. This needs some better error checking command! -nargs=0 -range=% Format \ ,!python -c "import sys, json, collections; print json.dumps(json.load(sys.stdin, object_pairs_hook=collections.OrderedDict), sort_keys=False, indent=2)" " Execute 'cmd' while redirecting output. " Delete all lines that do not match regex 'filter' (if not empty). " Delete any blank lines. " Delete ':' from start of each line. " Display result in a scratch buffer. function! s:Filter_lines(cmd, filter) let save_more = &more set nomore redir => lines silent execute a:cmd redir END let &more = save_more new setlocal buftype=nofile bufhidden=hide noswapfile put =lines g/^\s*$/d %s/^\s*\d\+:\s*//e if !empty(a:filter) execute 'v/' . a:filter . '/d' endif 0 endfunction command! -nargs=? Scriptnames call s:Filter_lines('scriptnames', )