Vim

My Vim Notes / Cheetsheet

Not necessarily a beginner cheetsheet for vim, rather a selection of tips and commands I didn’t have committed to memory at the time of writing. Hopefully something useful for others in here as well.

  • C-[ - faster alternative to esc
  • I and A - goto start/end of line and start editing
  • { and } - navigate by paragraph/block
  • [[ and ]] - navigate by function? larger
  • W and B - move forward/backward by whitespace words, often more useful than w and b
  • H M L - move to top, middle, bottom of screen
  • gg G - move to first/last line in document
  • fx - jump to next occurrence of x
  • tx - jump to before next occurrence of x
  • g; g, - navigate through changelist

Commands

  • q: - browse and re-run past commands
  • /C-f - re-search past searches
  • :so % - reload current file (vimrc)
  • :set list! - toggle displaying whitespace as characters
  • :colorscheme *light
  • :marks - view list of marks
  • :! command - run command
  • :!! - repeat last external shell command (super useful for development)
  • :.! command - run command and dump output into current window
  • @: - repeat last : command (any, includes :w etc)

Splits / Windows / Tabs

  • C-w _ - make split full height
  • C-w | - make split full width
  • gt gT - next/previous tab
  • C-wT - move current split to it’s own tab
  • ZZ - save and close current tab

Quickfix

  • :copen to view results
  • :cnext :cprev to navigate. (I map to [ and ])

Editing

  • J - join with line below
  • cc - change entire line
  • C - change rest of line
  • D - delete rest of line
  • gv - repeat last visual selection
  • C-n C-p - autocomplete word
  • C-x + C-l - autocomplete line
  • C-x + C-f - autocomplete a filename

Text Areas

  • da - delete a
  • ca - change a
  • di - delete inner
  • vi - visual mode

Combine with:

  • p paragraph
  • w word
  • t tag
  • ” ‘ ` ] } )

Essential Plugins

Some of this is custom to my bindings to various plugin commands.

ctrl-p

  • C-f and C-b to cycle modes (MRU and open buffers)
  • C-d to switch to searching by filename only
  • C-j C-k to nav results
  • C-t open in new tab
  • C-v open in new split
  • C-z to mark multiple files, C-o to open

vim-go

  • gd - goto definition
  • gb - go build
  • :GoKeyify
  • \gi :GoInfo
  • \gv :GoVet
  • \gtf :GoTestFunc
  • \gt :GoTest
  • \gtc :GoTestCompile

Fugitive

  • :Gstatus
  • :Ggrep - :copen after to examine results
  • :Gread - git checkout but operates on buffer
  • :Gmove - Handles git move plus buffer

Easymotion

Somehow supercharges vim’s already great navigation keybindings.

Taken from Easymotion docs:

  • \f{char} - Find {char} to the right. See |f|.
  • \F{char} - Find {char} to the left. See |F|.
  • \t{char} - Till before the {char} to the right. See |t|.
  • \T{char} - Till after the {char} to the left. See |T|.
  • \w - Beginning of word forward. See |w|.
  • \W - Beginning of WORD forward. See |W|.
  • \b - Beginning of word backward. See |b|.
  • \B - Beginning of WORD backward. See |B|.
  • \e - End of word forward. See |e|.
  • \E - End of WORD forward. See |E|.
  • \g - End of word backward. See |ge|.
  • \g - End of WORD backward. See |gE|.
  • \j - Line downward. See |j|.
  • \k - Line upward. See |k|.
  • \n - Jump to latest “/” or “?” forward. See |n|.
  • \N - Jump to latest “/” or “?” backward. See |N|.
  • \s - Find(Search) {char} forward and backward.

Buffergator

  • \b \B - select from open buffers
  • C-N C-P - flip through and view buffers, full path is at the bottom
  • \to \tc - show open tabs
  • C-V C-S C-T - open in new splits / tabs
  • gb gB - flip through MRU buffers
  • [num]CR - open buf number in prev window

NerdCommenter

  • \cc - toggle comment
  • \cSPACE - toggle comment of selected line
  • \cs - pretty block commenting

Colorschemes

I have spent way too much time looking for the perfect vim colorscheme. My current favorite is Seoul256. I use the following custom commands depending on atmospheric conditions, because obviously you have to match your vim colorscheme to atmospheric conditions:

command! Light let g:seoul256_background = 256 | colorscheme seoul256
command! Medium let g:seoul256_background = 254 | colorscheme seoul256
command! Dark let g:seoul256_background = 237 | colorscheme seoul256