VIM

Visuals

The following commands can assist setting up visual guides. Think having a visual reference for indentation levels, for example

Find out more about each option by issuing :h '<option>'

  • (Ex-mode) :set colorcolumn=N: highlights column N
  • (Ex-mode) :set cc=X,Y,Z: highlights columns X, Y, and Z
  • (Ex-mode) :set cc=: clears previously set colorcolumns
  • (Ex-mode) :set cursorcolumn: highlights the column under the cursor
  • (Ex-mode) :set nocuc: unsets cursorcolumn
  • (Ex-mode) :set cursorline: highlights the line under the cursor
  • (Ex-mode) :set nocul: unsets cursorline
  • (Ex-mode) :hi ColorColumn guibg=#300000: highlights all colorcolumns with a dark red
  • (Ex-mode) :hi CursorColumn guibg=#300000: same as the above, but for cursorcolumn

Movement

  • (NORMAL) 3w: jump 3 words forward (cursor is placed at the beginning of the Nth word)
  • (NORMAL) 5b: jump 5 words backward
  • (NORMAL) gg: jump to top (file)
  • (NORMAL) G: jump to bottom (file)
  • (NORMAL) zz: position line under the cursor at the middle of the screen
  • (Ex-mode) :N: jump to line #N
  • $ vim <file> +N: open <file> placing the cursor at line N

Splitting

  • (Ex-mode) :sp <file>: open <file> in a horizontally-split window
  • (Ex-mode) :term: open a terminal in a horizontally-split window
  • (Ex-mode) :vsp <file>: open <file> in a vertically-split window
  • (Ex-mode) :vert term: open a terminal in a vertically-split window
  • (NORMAL) Ctrl+ww: cycle between splits (replace second w with h|j|k|l to move in a specific direction between splits)

Text manipulation

  • (Ex-mode) :4,12s/replace_me/replaced/g: replace all (/g) instances of replace_me in lines 4 through 12 with replaced
  • (Ex-mode) :50,100d: delete lines 50 through 100
  • (NORMAL) dd: delete entire line under cursor
  • (NORMAL) yy: yank (copy) entire line under cursor

Misc

  • $ vim -x <file>: create a blowfish2-encrypted <file>
  • (Ex-mode) :tabnew <file>: open <file> in a new tab
  • (NORMAL) Shift+K: view API reference for the function under the cursor (if supported/found)
  • (NORMAL) gt: go to next tab
  • (NORMAL) m<char>: set a mark using char. Example: ma sets a mark for the letter a
  • (NORMAL) '<char>: jump to mark char. Example: 'a jump to mark a
  • (NORMAL) ZZ: quit, saving changes
  • (NORMAL) ZQ: quit without saving