Modes

  • esc - normal mode
  • : - command mode

Exit

  • :wq - save changes
  • :q! - discard changes

Move

  • b/B or w/W - move to start of word/token

  • e/E - move to end of word/token

  • 0 - go to start of line

  • ^ - go to first non-blank char of line

  • $ - go to end of line

  • gg - go to start of file

  • G - go to end of file

  • xgg/xG/:x - go to line x

  • H/M/L - top/middle/bottom of screen

  • Ctrl + …

    • y/e - up/down 1 line
    • d/u - up/down .5 screen
    • b/f - back/forward 1 screen
    • o/i - back/forward through jump history

Insert

  • a/A - insert after cursor/line
  • i/I - insert in front of cursor/line
  • O/o - open a new line above/below current

Selection

  • v - by char
    • aw/iw - select a word with/without space in front
    • u/U - change case
  • V - by line
  • ctrl + v - by block

Yank/copy

  • yaw/yiw - word with/without trailing space after

  • ytx - from cursor to x

  • yfx - from cursor to x, inclusive

  • yy - line

  • xyy - x lines

Paste

  • P - paste before cursor
  • p - paste after cursor

Cut

  • x/X - cut current/prev char

  • d<.> - cut .

    • :x,yd - line x to line y
      • x = . and y = $ - current to end of file
    • :g(!)/pattern/d - lines (not) containing pattern
      • pattern = ^$ - all blank lines

Cut and edit in place

  • r - replace current char

  • R - enter replace mode

  • s - sub current char (activates insert mode)

  • S - sub current line (activates insert mode)

    • :s/old/new - subs first old in current line
    • :s/old/new/g - subs all ‘old’s in current line
    • :x,ys/old/new/g - subs all ‘old’s in range with new
    • :%s/old/new/g - subs all ‘old’s with new
      • use gc to get confirmation each time
  • c<.> - cut ., enter insert mode

    • C - cut to end of line

Undo/redo

  • . - repeat last command
  • u/:u/:undo - undo
  • ctrl + r - redo
  • /pattern / ?pattern - search forward/backward for pattern
    • * / # - jump to next/prev
  • n/N - repeat the search in the same/opposite direction