Skip to main content
TellaDev

38 entries

Vim

Essential Vim commands and shortcuts for efficient text editing

38 commands

i
Enter Insert mode before the cursor
Press i then type text
a
Enter Insert mode after the cursor
Press a to append after cursor
o
Open a new line below and enter Insert mode
Press o to start typing on new line below
O
Open a new line above and enter Insert mode
Press O to insert line above
Esc
Return to Normal mode from any other mode
Press Esc to return to Normal mode
v
Enter Visual (character) mode
Press v then move to select chars
V
Enter Visual Line mode (selects entire lines)
Press V to select entire line
Ctrl+v
Enter Visual Block mode (column selection)
Ctrl+v then I to insert on multiple lines
h j k l
Move cursor left, down, up, right
10j moves 10 lines down
w / b
Jump to next / previous word start
3w jumps forward 3 words
0 / $
Move to start / end of the current line
0 goes to column 1, $ to end
gg / 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 42
Ctrl+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 lines
yy
Yank (copy) the current line
yy then p pastes the line below
p / P
Paste after / before the cursor
p pastes after, P pastes before
u
Undo the last change
u undoes last change
Ctrl+r
Redo the last undone change
Ctrl+r redoes the undo
cw
Change (delete and enter Insert mode) from cursor to end of word
cw then type to replace word
ciw
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 backwards
n / 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 indent
gv
Reselect the last visual selection
gv reselects previous selection
qa
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