Cheatsheets
Vim
38 entries
Vim
Essential Vim commands and shortcuts for efficient text editing
38 commands
CommandDescriptionExample
i
Enter Insert mode before the cursor
Press i then type texta
Enter Insert mode after the cursor
Press a to append after cursoro
Open a new line below and enter Insert mode
Press o to start typing on new line belowO
Open a new line above and enter Insert mode
Press O to insert line aboveEsc
Return to Normal mode from any other mode
Press Esc to return to Normal modev
Enter Visual (character) mode
Press v then move to select charsV
Enter Visual Line mode (selects entire lines)
Press V to select entire lineCtrl+v
Enter Visual Block mode (column selection)
Ctrl+v then I to insert on multiple linesh j k l
Move cursor left, down, up, right
10j moves 10 lines downw / b
Jump to next / previous word start
3w jumps forward 3 words0 / $
Move to start / end of the current line
0 goes to column 1, $ to endgg / G
Go to the first / last line of the file
gg goes to line 1, G to last line:<n>
Go to line number n (e.g., :42)
:42 jumps to line 42Ctrl+d / Ctrl+u
Scroll down / up half a page
Ctrl+d scrolls half page down%
Jump to the matching bracket, parenthesis, or brace
Place cursor on { to jump to }dd
Delete (cut) the current line
3dd deletes 3 linesyy
Yank (copy) the current line
yy then p pastes the line belowp / P
Paste after / before the cursor
p pastes after, P pastes beforeu
Undo the last change
u undoes last changeCtrl+r
Redo the last undone change
Ctrl+r redoes the undocw
Change (delete and enter Insert mode) from cursor to end of word
cw then type to replace wordciw
Change the entire word under the cursor
ciw replaces word under cursor.
Repeat the last change
dd then . deletes next line too/<pattern>
Search forward for a pattern
/function searches for 'function'?<pattern>
Search backward for a pattern
?import searches backwardsn / N
Jump to next / previous search match
n goes to next match:%s/old/new/g
Replace all occurrences of 'old' with 'new' in the file
:%s/foo/bar/gc (confirm each):w
Save (write) the current file
:w saves the file:q
Quit Vim (fails if there are unsaved changes)
:q exits vim:wq
Save and quit
:wq saves and exits:q!
Quit without saving, discarding all changes
:q! discards changes and exits:e <file>
Open a file for editing
:e ~/.bashrc>G
Indent from the current line to end of file
Select lines then > to indentgv
Reselect the last visual selection
gv reselects previous selectionqa
Start recording a macro into register 'a'
qa starts recording into 'a'q
Stop recording the current macro
q stops recording@a
Play back the macro stored in register 'a'
@a replays macro 'a'@@
Repeat the last played macro
@@ repeats last macro