vim
Vim Cheat Sheet
📍 Basic Cursor Movements
Command | Action | Description |
---|---|---|
k |
Move up | Moves the cursor one line up. |
j |
Move down | Moves the cursor one line down. |
h |
Move left | Moves the cursor one character to the left. |
l |
Move right | Moves the cursor one character to the right. |
e |
Jump to word end | Moves the cursor to the end of the current or next word. |
b |
Jump to word start | Moves the cursor to the beginning of the current or previous word. |
$ |
Jump to line end | Moves the cursor to the end of the current line. |
0 |
Jump to line start | Moves the cursor to the beginning of the current line. |
H |
Move to top of screen | Moves the cursor to the first visible line on the screen. |
M |
Move to middle of screen | Moves the cursor to the middle visible line on the screen. |
L |
Move to bottom of screen | Moves the cursor to the last visible line on the screen. |
w |
Jump to next word start | Moves the cursor to the beginning of the next word. |
✏️ Editing Basics
Command | Action | Description |
---|---|---|
i |
Insert mode | Enters insert mode to type at the current cursor position. |
I |
Insert at start of line | Enters insert mode at the beginning of the current line. |
a |
Append mode | Enters insert mode to type after the current cursor position. |
A |
Append to line end | Enters insert mode at the end of the current line. |
o |
Insert new line below | Creates a new line below the current line and enters insert mode. |
O |
Insert new line above | Creates a new line above the current line and enters insert mode. |
r |
Replace single character | Replaces the character under the cursor with the next typed character. |
R |
Replace mode | Enters overwrite mode to replace multiple characters. |
esc |
Exit insert mode | Exits insert or replace mode and returns to normal mode. |
🚀 Advanced Cursor Navigation
Command | Action | Description |
---|---|---|
fw |
Search next w |
Moves the cursor to the next occurrence of the character w on the current line. |
Fw |
Search previous w |
Moves the cursor to the previous occurrence of the character w . |
tw |
Jump before next w |
Moves the cursor just before the next occurrence of w on the line. |
Tw |
Jump before previous w |
Moves the cursor just before the previous occurrence of w . |
; |
Repeat last search | Repeats the last f , F , t , or T command. |
, |
Reverse last search | Repeats the last f , F , t , or T command in the opposite direction. |
5j |
Move down 5 lines | Moves the cursor 5 lines down. |
5k |
Move up 5 lines | Moves the cursor 5 lines up. |
✂️ Advanced Text Editing
Command | Action | Description |
---|---|---|
yy |
Yank line | Copies the entire current line. |
y$ |
Yank to line end | Copies from the cursor position to the end of the line. |
ye |
Yank to word end | Copies from the cursor position to the end of the word. |
dd |
Delete current line | Deletes the entire current line. |
5dd |
Delete 5 lines | Deletes the next 5 lines starting from the current line. |
d2w |
Delete 2 words | Deletes the next two words starting from the cursor position. |
D |
Delete to line end | Deletes from the current cursor position to the end of the line. |
p |
Paste below | Pastes the yanked or deleted content after the current line. |
P |
Paste above | Pastes the yanked or deleted content before the current line. |
✂️ Vim Editing Shortcuts ⌨
Shortcut | Action |
---|---|
P |
Paste before cursor |
u |
Undo |
U |
Undo all changes to current line |
^r |
Redo |
. |
Repeat last change |
5. |
Repeat last change 5 times |
de |
Delete (cut) to end of word |
d$ |
Delete (cut) to end of line |
🔄 Vim Navigation Shortcuts
Shortcut | Action |
---|---|
^ |
Move to first non-whitespace char |
20| |
Go to column 20 |
% |
Go to matching parenthesis or bracket |
^o |
Move to older position |
^i |
Move to newer position |
zt |
Scroll current line to top of window |
✍️ Vim Editing Commands
Shortcut | Action |
---|---|
:w filename |
Write selection to ‘filename’ |
v |
Visual mode select characters |
V |
Visual mode highlight lines |
` |
Swap case |
> |
Shift right |
< |
Shift left |
c |
Change highlighted text |
y |
Yank (copy) highlighted text |
d |
Cut highlighted text |
= |
Re-indent selection |
🖥️ Vim Window Management Shortcuts
Shortcut | Action |
---|---|
:e filename |
Set current buffer to ‘filename’ |
:sp |
New window above |
:vs |
New window to left |
:q |
Close current window |
:qa |
Close all windows |
💾 Vim Save & File Operations
Shortcut | Action |
---|---|
:q! |
Quit without saving |
:wq |
Save and exit |
:x |
Save and exit if modified |
:r filename |
Read and insert ‘filename’ |
:r !cmd |
Execute and insert results of ‘cmd’ |
:!rm filename |
Delete ‘filename’ |
:e |
Open new file |
^g |
Show file info |
ga |
Show character info |
:w |
Save changes |
:q |
Quit |
📍 Vim Bookmarks & Position Navigation
Shortcut | Action |
---|---|
:marks |
Show bookmarks |
ma |
Mark position ‘a’ |
`a |
Go to bookmark position ‘a’ |
`` | Go to previous position |
🔍 Vim Search & Replace Shortcuts
Shortcut | Action |
---|---|
:s/foo/bar |
Replace first ‘foo’ with ‘bar’ on line |
:s/foo/bar/g |
Replace all ‘foo’ with ‘bar’ on line |
:%s/foo/bar/g |
Replace all ‘foo’ with ‘bar’ in file |
:%s/foo/bar |
Replace first ‘foo’ with ‘bar’ on every line |
:s/foo/bar/gc |
Confirm replace all ‘foo’ with ‘bar’ on line |
:s/foo/bar/i |
Ignore case replace first ‘foo’ with ‘bar’ |
rx |
Replace current char with ‘x’ |
:%s/foo/bar/gc |
Confirm replace all ‘foo’ with ‘bar’ in file |
:2,9s/foo/bar/g |
Replace all ‘foo’ with ‘bar’ between lines 2 and 9 |
🔎 Vim Search Commands & Options
Shortcut | Action |
---|---|
/foo |
Search forwards for ‘foo’ |
?foo |
Search backwards for ‘foo’ |
n |
Search next |
N |
Search previous |
* |
Search for current word forward |
:set nois |
Turn off incremental search |
:set ic |
Set ignore case |
:set is |
Set incremental search |
:set hls |
Set highlight matching phrases |
🖥️ Vim Command Execution & Autocomplete Shortcuts
Shortcut | Action |
---|---|
vim -t foo |
Start editing where ‘foo’ is defined |
:help cmd |
Lookup ‘cmd’ in help |
:make |
Run make |
:!ls |
Execute ‘ls’ command |
^p |
Move autocomplete backward |
^x |
Move language autocomplete forward |
^o |
Move language autocomplete backward |
K |
Look up word in man pages |
yw |
Yank to beginning of next word |
This post is licensed under
CC BY 4.0
by the author.