Based on my most used command when doing daily text/code editing.

Normal Mode

  • gg: move the cursor to the beginning of the file
  • i: enter insert mode
  • x: Cut character
  • dw: Cut word
  • dd: Cut full line
  • yw: Copy word
  • yy: Copy full line
  • p: Paste
  • :1: Go to line number 1
  • :w: Write the file i.e save
  • :q: Quit
  • :q!: Quite without saving
  • :wq: Write and quit

Insert Mode

  • esc: back to normal mode

Use Cases

  1. Select entire file in visual mode.
    1. Steps:
    2. ensure we are in normal mode
    3. Move the cursor to the beginning of the file using gg
    4. Enter visual line mode by pressing V
    5. Move to the end of the file by pressing G, which selects all content from the start to the end of the file
  2. Key sequence: ggVG
  3. delete multiple lines that contains a word: :g/word/d
  4. Replace word in specific line ranges:
    1. :10,20s/old-word/new-word/g from line 10 to line 20
    2. :,$s/old-word/new-word/g current line to end of line
    3. :1,.s/old-word/new-word/g first line to current line