VIM Commands Cheatsheet no water, just straight to the point, such as - how to save and exit vim editor?!
Basic Navigation
Command | Description |
---|
h | Move left |
j | Move down |
k | Move up |
l | Move right |
w | Jump forward to the start of the next word |
b | Jump backward to the start of the previous word |
$ | Go to the end of the line |
0 | Go to the beginning of the line |
gg | Go to the first line of the file |
G | Go to the last line of the file |
ctrl + f | Page down |
ctrl + b | Page up |
Editing & Inserting
Command | Description |
---|
i | Insert text before the cursor (insert mode) |
a | Insert text after the cursor (insert mode) |
o | Insert a new line below the current one |
O | Insert a new line above the current one |
dd | Delete the current line |
dw | Delete the current word |
x | Delete the character under the cursor |
r | Replace a single character |
R | Replace mode (overwrites text) |
yy | Yank (copy) the current line |
p | Paste after the cursor |
P | Paste before the cursor |
Command Mode
To enter command mode, press :
.
Command | Description |
---|
:w | Save the file |
:q | Quit VIM |
:wq | Save and quit |
:q! | Quit without saving (force quit) |
:x | Save and quit (similar to :wq ) |
:e <filename> | Open a new file |
:set nu | Show line numbers |
:set nonu | Hide line numbers |
:help | Open VIM help documentation |
Search and Replace
Command | Description |
---|
/ | Search forward |
n | Go to the next search result |
N | Go to the previous search result |
:%s/old/new/g | Replace all instances of old with new in the entire file |
:%s/old/new/gc | Replace all instances with confirmation |
Undo and Redo
Command | Description |
---|
u | Undo the last change |
ctrl + r | Redo the last undone change |
Visual Mode
To enter visual mode, press v
. This allows you to select text.
Command | Description |
---|
v | Visual mode (character-by-character selection) |
V | Visual line mode (select entire lines) |
ctrl + v | Visual block mode (select rectangular blocks) |
y | Yank (copy) the selected text |
d | Delete the selected text |