Linux & Terminal63 entries

Vim Editor

Vim modes, navigation, editing, search, and plugin essentials

1Modes

i
Enter Insert mode (before cursor)
a
Enter Insert mode (after cursor)
I
Insert at beginning of line
A
Insert at end of line
o
Open new line below and enter Insert mode
O
Open new line above and enter Insert mode
v
Enter Visual mode (character selection)
V
Enter Visual Line mode (line selection)
Ctrl+v
Enter Visual Block mode (column selection)
Esc
Return to Normal mode

2Navigation

h j k l
Move left, down, up, right
w / W
Jump forward to next word / WORD
b / B
Jump backward to previous word / WORD
e / E
Jump to end of word / WORD
0
Jump to beginning of line
^
Jump to first non-blank character
$
Jump to end of line
gg
Go to first line of file
G
Go to last line of file
<n>G
Go to line number n
Ctrl+d / Ctrl+u
Half-page down / up
Ctrl+f / Ctrl+b
Full-page forward / backward
%
Jump to matching bracket

3Editing

x
Delete character under cursor
dd
Delete (cut) entire line
dw
Delete to end of word
d$
Delete to end of line
D
Delete to end of line (same as d$)
cc
Change entire line (delete and enter Insert mode)
cw
Change word
C
Change to end of line
r<char>
Replace single character
R
Enter Replace mode (overwrite text)
J
Join current line with next line
~
Toggle case of character

4Copy & Paste

yy
Yank (copy) entire line
yw
Yank word
y$
Yank to end of line
p
Paste after cursor
P
Paste before cursor
"+y
Yank to system clipboard
"+p
Paste from system clipboard

5Search & Replace

/<pattern>
Search forward for pattern
?<pattern>
Search backward for pattern
n
Repeat search in same direction
N
Repeat search in opposite direction
*
Search for word under cursor (forward)
#
Search for word under cursor (backward)
:%s/old/new/g
Replace all in file
:%s/old/new/gc
Replace all with confirmation
:s/old/new/g
Replace all in current line

6Undo & Redo

u
Undo last change
Ctrl+r
Redo last undone change
.
Repeat last command

7File Operations

:w
Save file
:w <filename>
Save as new file
:q
Quit (fails if unsaved changes)
:q!
Quit without saving
:wq
Save and quit
:x
Save and quit (only writes if changed)
ZZ
Save and quit (Normal mode)
:e <file>
Open a file
:bn / :bp
Next / previous buffer