Essential Vim keyboard shortcuts and commands. Navigate, edit, search, and manage files in Vim. Complete reference for beginners and pros.
| Shortcut | Description |
h | Move cursor left one character |
j | Move cursor down one line |
k | Move cursor up one line |
l | Move cursor right one character |
w | Jump forward to start of next word |
W | Jump forward to start of next WORD (space-delimited) |
b | Jump backward to start of previous word |
B | Jump backward to start of previous WORD (space-delimited) |
e | Jump forward to end of current word |
E | Jump forward to end of current WORD (space-delimited) |
0 | Move to the beginning of the line |
^ | Move to the first non-blank character of the line |
$ | Move to the end of the line |
gg | Go to the first line of the file |
G | Go to the last line of the file |
5G or :5 | Go to line 5 (replace 5 with any line number) |
H | Move cursor to top of screen (High) |
M | Move cursor to middle of screen (Middle) |
L | Move cursor to bottom of screen (Low) |
Ctrl + f | Scroll forward one full screen (page down) |
Ctrl + b | Scroll backward one full screen (page up) |
Ctrl + d | Scroll down half a screen |
Ctrl + u | Scroll up half a screen |
% | Jump to matching bracket ( ), [ ], or { } |
f{char} | Move forward to next occurrence of {char} on current line |
F{char} | Move backward to previous occurrence of {char} on current line |
t{char} | Move forward to just before {char} on current line |
; | Repeat last f, F, t, or T motion forward |
, | Repeat last f, F, t, or T motion backward |
} | Jump to next paragraph (blank line) |
{ | Jump to previous paragraph (blank line) |
| Shortcut | Description |
x | Delete the character under the cursor |
X | Delete the character before the cursor |
dd | Delete (cut) the entire current line |
dw | Delete from cursor to start of next word |
d$ or D | Delete from cursor to the end of the line |
d0 | Delete from cursor to the beginning of the line |
dgg | Delete from current line to the beginning of the file |
dG | Delete from current line to the end of the file |
d% | Delete to matching bracket |
cc | Change (replace) the entire current line |
cw | Change from cursor to start of next word |
c$ or C | Change from cursor to the end of the line |
s | Delete character under cursor and enter insert mode |
S | Delete entire line and enter insert mode (same as cc) |
r{char} | Replace the character under cursor with {char} |
R | Enter replace mode (overwrite characters as you type) |
yy | Yank (copy) the entire current line |
yw | Yank from cursor to start of next word |
y$ | Yank from cursor to the end of the line |
p | Paste after cursor (or below current line for full lines) |
P | Paste before cursor (or above current line for full lines) |
u | Undo the last change |
Ctrl + r | Redo the last undone change |
. | Repeat the last editing command |
J | Join the current line with the next line |
~ | Toggle case of the character under cursor |
>> | Indent the current line |
<< | Un-indent the current line |
| Command | Description |
/pattern | Search forward for pattern |
?pattern | Search backward for pattern |
n | Repeat search in the same direction |
N | Repeat search in the opposite direction |
* | Search forward for the word under the cursor |
# | Search backward for the word under the cursor |
:s/old/new/ | Replace first occurrence of old with new on the current line |
:s/old/new/g | Replace all occurrences of old with new on the current line |
:%s/old/new/g | Replace all occurrences of old with new in the entire file |
:%s/old/new/gc | Replace all occurrences with confirmation for each match |
:noh | Clear search highlighting |
| Shortcut | Description |
v | Enter visual (character) mode — select text character by character |
V | Enter visual line mode — select entire lines |
Ctrl + v | Enter visual block mode — select a rectangular block |
gv | Reselect the last visual selection |
o | Move to the other end of the selection (in visual mode) |
d | Delete the selected text (in visual mode) |
y | Yank (copy) the selected text (in visual mode) |
c | Change the selected text (in visual mode) |
> | Indent the selected text (in visual mode) |
< | Un-indent the selected text (in visual mode) |
~ | Toggle case of selected text (in visual mode) |
U | Uppercase selected text (in visual mode) |
u | Lowercase selected text (in visual mode) |
| Command | Description |
:w | Save (write) the current file |
:w filename | Save as a new file with the given name |
:q | Quit Vim (fails if there are unsaved changes) |
:q! | Quit without saving (force quit) |
:wq or :x | Save and quit |
ZZ | Save and quit (shortcut, no colon needed) |
ZQ | Quit without saving (shortcut, no colon needed) |
:e filename | Open a file for editing |
:e! | Reload the current file, discarding changes |
:sp filename | Open a file in a horizontal split |
:vsp filename | Open a file in a vertical split |
:r filename | Read and insert a file below the cursor |
:r !command | Insert the output of a shell command below the cursor |
| Command | Description |
:ls or :buffers | List all open buffers |
:bn | Switch to the next buffer |
:bp | Switch to the previous buffer |
:bd | Close (delete) the current buffer |
:b2 | Switch to buffer number 2 |
Ctrl + w s | Split the window horizontally |
Ctrl + w v | Split the window vertically |
Ctrl + w w | Cycle through open windows |
Ctrl + w h | Move to the window on the left |
Ctrl + w j | Move to the window below |
Ctrl + w k | Move to the window above |
Ctrl + w l | Move to the window on the right |
Ctrl + w q | Close the current window |
Ctrl + w o | Close all windows except the current one |
Ctrl + w = | Make all windows equal size |
Ctrl + w + | Increase current window height |
Ctrl + w - | Decrease current window height |
:tabnew | Open a new tab |
:tabn or gt | Go to the next tab |
:tabp or gT | Go to the previous tab |
:tabclose | Close the current tab |
| Command | Description |
m{a-z} | Set a local mark (e.g., ma sets mark a in current buffer) |
m{A-Z} | Set a global mark (works across files) |
'{mark} | Jump to the line of the mark (e.g., 'a) |
`{mark} | Jump to the exact position of the mark (e.g., `a) |
'' | Jump back to the line before the last jump |
`` | Jump back to the exact position before the last jump |
:marks | List all current marks |
:delmarks a | Delete mark a |
:delmarks! | Delete all lowercase marks |