Vim Commands Cheat Sheet
A concise reference for the most common and essential Vim commands, from basic editing to advanced operations.
Exiting
Command | Description |
---|---|
:w | Write (save) the current file. |
:wa | Write all open files. |
:q | Quit the current file. |
:qa | Quit all open files. |
:q! / ZQ | Quit and discard any unsaved changes. |
:wq / :x | Write (save) and quit. |
ZZ | A shortcut for :wq . |
:wqa | Write and quit all open files. |
Modes
Command | Description |
---|---|
i | Insert mode (before cursor). |
a | Append mode (after cursor). |
o / O | Open a new line below/above and enter Insert mode. |
v | Visual mode (character-wise). |
V | Visual mode (line-wise). |
<C-v> | Visual mode (block-wise). |
: | Command-Line mode. |
R | Replace mode. |
Esc | Return to Normal mode. |
Basic Movement
Command | Description |
---|---|
h j k l | Move left, down, up, right. |
w / b | Move forward/backward by one word. |
e | Move to the end of the current word. |
0 / ^ | Move to the start / first non-blank char of the line. |
$ / g_ | Move to the end / last non-blank char of the line. |
gg / G | Go to the first / last line of the file. |
{n}G | Go to line number {n} . |
H / M / L | Go to the High, Middle, or Low part of the screen. |
Editing Text
Deleting, Changing, and Replacing
Command | Description |
---|---|
x | Delete character under the cursor. |
d{motion} | Delete text over {motion} . |
dd | Delete the current line. |
D | Delete from cursor to the end of the line. |
c{motion} | Change text over {motion} . |
cc | Change the entire line. |
C | Change to the end of the line. |
r{char} | Replace the character under the cursor with {char} . |
s | Substitute character and enter Insert mode. |
. | Repeat the last change. |
u / <C-r> | Undo / Redo the last change. |
Yank (Copy) and Put (Paste)
The y
command yanks (copies) text, and p
puts (pastes) it.
Command | Description |
---|---|
y{motion} | Yank text over {motion} . |
yy | Yank the current line. |
Y | Yank the current line (same as yy ). |
p / P | Put (paste) after / before the cursor. |
Changing Case
Command | Description |
---|---|
~ | Switch case of the character under the cursor. |
gU{motion} | Convert text over {motion} to UPPERCASE. |
gu{motion} | Convert text over {motion} to lowercase. |
gUU / guu | Make the entire line UPPERCASE / lowercase. |
Search and Replace
Searching
Command | Description |
---|---|
/pattern | Search forward for pattern . |
?pattern | Search backward for pattern . |
* / # | Search forward/backward for the word under the cursor. |
n / N | Go to the next / previous search match. |
Replacing
Command | Description |
---|---|
:s/old/new/g | Replace all old with new on the current line. |
:%s/old/new/g | Replace all old with new in the entire file. |
:%s/old/new/gc | Replace throughout the file, with confirmation for each. |
Working with Multiple Files (Buffers)
Command | Description |
---|---|
:e {file} | Edit a file in a new buffer. |
:ls | List all open buffers. |
:b{n} | Go to buffer number {n} . |
:bn / :bp | Go to the next / previous buffer. |
:bd | Buffer delete (close the current buffer). |
Window Management
Command | Description |
---|---|
:sp {file} | Split the window horizontally. |
:vsp {file} | Vertically split the window. |
<C-w>s | Horizontal split. |
<C-w>v | Vertical split. |
<C-w>w | Switch to the next window. |
<C-w>h/j/k/l | Move to the window left/down/up/right. |
<C-w>q | Quit (close) the current window. |
<C-w>= | Make all windows equal size. |
Marks and Jumps
Marks are like bookmarks. Jumps are cursor movements that are saved in a list.
Command | Description |
---|---|
m{a-z} | Set a mark named {a-z} at the cursor position. |
{a-z} | Jump to the line of mark {a-z} . |
'a | Jump to the beginning of the line of mark a . |
:marks | List all marks. |
<C-o> / <C-i> | Jump to the older / newer position in the jump list. |
Macros
Macros record a sequence of keystrokes that you can replay.
q{a-z}
- Start recording a macro into register{a-z}
.- Perform your sequence of commands.
q
- Stop recording.@{a-z}
- Execute the macro from register{a-z}
.@@
- Replay the last executed macro.