Skip to content

Instantly share code, notes, and snippets.

@webbower
Last active July 22, 2024 23:24
Show Gist options
  • Save webbower/1602d558472780a6a6045b56aa694c9b to your computer and use it in GitHub Desktop.
Save webbower/1602d558472780a6a6045b56aa694c9b to your computer and use it in GitHub Desktop.
Vim Learning

Vim Cheatsheet

Motions

Navigation

  • w: Move [] -> next word
  • W: Move [] -> next WORD
  • e: Move [] -> word end
  • E: Move [] -> WORD end
  • $: Move [] -> line end
  • 0 (zero): Move [] -> line start
  • b: [] -> prev word
  • B: [] -> prev WORD
  • Ctrl-G: Show [] location in footer
  • G: [] -> bottom of file
  • gg: [] -> top of file
  • <num>G: [] -> to line <num>
  • Ctrl-O: [] -> back history [] location
  • Ctrl-I: [] -> forward history [] location
  • %: [] -> matching paren (), [], {}
  • Ctrl-W Ctrl-W: jump between windows

Editing

  • i: Insert mode at []
  • a: Insert mode after []
  • A: Insert mode at EOL
  • o: Insert mode on newline below []
  • O: Insert mode on newline above []
  • p: Put removed content after []
  • P: Put removed content before []
  • r<char>: Replace char at [] with <char>
  • R: Replace (overwrite) mode at []
  • y: Yank (copy)
    • yy: Yank whole line
    • yw: Yank [] -> next word
    • ye: Yank [] -> end of word
    • y$: Yank [] -> end of line
  • d: Delete operator
    • dw: Delete [] -> next word start
    • de: Delete [] -> current word end
    • d$: Delete [] -> line end
    • <num = 1>dd: Delete whole lines current and down
  • c: Change (remove current and enter Insert mode)
    • cw: Change [] -> next word
    • ce: Change [] -> end of word
    • c$: Change [] -> end of line
    • cC: Change whole line
  • <num><motion>: repeat action times
  • <operator><num><motion>: repeat action times in direction
  • u: Undo last command
  • U: Revert whole line to previous save
  • Ctrl-R: Redo last undone commend

Search

  • /<phrase>: Search for <phrase> forward from [] (append \c to ignore case)
  • ?<phrase>: Search for <phrase> backward from [] (append \c to ignore case)
  • n: [] -> next result
  • N: [] -> prev result
  • :s/<old>/<new>/g: substitute command. Replace all <old> with <new> in the current line (g flag is global)
  • :<line1>,<line2>s/<old>/<new>/g: substitute command. Replace all <old> with <new> in the <line1>,<line2> range (g flag is global)
  • :%s/<old>/<new>/g: substitute command. Replace all <old> with <new> in the whole file (g flag is global)
  • :%s/<old>/<new>/gc: substitute command. Replace all <old> with <new> in the whole file with prompt (g flag is global)
  • :[no]hlsearch/[no]hls: toggle highlight of current search

External Commands

  • :!<cmd>: execute external command (! prefix executes the command anywhere)
  • :w <filename>: save current buffer to <filename>
  • v <motion> w <filename>: save current selection to <filename>
  • :r <filename>: insert contents of <filename> below []
  • :r !<cmd>: insert output of <cmd> below []

Help

  • :help: show Help
  • :help <cmd>: show Help for specific <cmd>
  • :help v_<cmd>: show Help for specific <cmd> in Visual mode
  • :help i_<cmd>: show Help for specific <cmd> in Insert mode
  • :help :<cmd>: show Help for specific command-line <cmd>
  • :help c_<???>: show Help for specific command-line editing <???>
  • :help <option>: show Help for <option>
  • Ctrl-]: show help for current word/tag
    • Ctrl-T | Ctrl-O: go back from current word/tag

Options

  • :set [no]<option>: enable/disable <option>
    • [no]ic: ignore case
    • [no]hlsearch/[no]hls: highlight search
    • [no]incsearch/[no]is: incremental search
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment