Vim Cheatsheet
Commands for Beginners and Advanced Users
posted by Sink
updatedVim is a powerful text editor that can enhance your productivity once you master its commands. Whether you're a beginner or looking to refine your skills, this cheat sheet provides quick access to essential Vim commands.
Getting Started with Vim Modes
Vim operates in several modes, each serving a unique purpose:
- Normal Mode: Default for navigation and commands.
- Insert Mode: For text insertion and editing.
- Visual Mode: For text selection.
- Command-line Mode: For executing commands.
Switching modes efficiently is crucial for effective Vim usage.
Basic Navigation Commands
Quickly navigate your document with these commands:
Command | Description |
---|---|
h , j , k , l | Move left, down, up, and right |
0 | Go to the beginning of the line |
$ | Move to the end of the line |
w | Jump to the start of the next word |
b | Jump to the start of the previous word |
gg | Go to the top of the file |
G | Go to the bottom of the file |
Ctrl + u | Scroll up by half a screen |
Ctrl + d | Scroll down by half a screen |
Inserting Text
Switch to Insert Mode to add text:
Command | Description |
---|---|
i | Insert before the cursor |
I | Insert at the start of the line |
a | Append after the cursor |
A | Append at the end of the line |
o | Open a new line below the cursor |
O | Open a new line above the cursor |
Editing and Deleting Text
Modify text quickly with these commands:
Command | Description |
---|---|
x | Delete the character under the cursor |
dw | Delete to the start of the next word |
d$ | Delete to the end of the line |
dd | Delete the entire line |
u | Undo the last action |
Ctrl + r | Redo the last undone change |
yy | Copy (yank) the entire line |
p | Paste below the cursor |
P | Paste above the cursor |
Copying and Pasting from Outside Neovim
To copy and paste between Neovim and your system clipboard, use:
Command | Description |
---|---|
"+y | Copy selected text to the system clipboard |
"+p | Paste text from the system clipboard |
Text Selection in Visual Mode
Select text by entering Visual Mode:
Command | Description |
---|---|
v | Start character-by-character selection |
V | Start line selection |
Ctrl + v | Start block selection |
Searching and Replacing Text
Find and replace text efficiently:
Command | Description |
---|---|
/text | Search forward for text |
?text | Search backward for text |
n | Next search match |
N | Previous search match |
:%s/old/new/g | Replace all old with new |
:s/old/new/g | Replace in the current line |
Working with Multiple Files and Buffers
Manage multiple files with these commands:
Command | Description |
---|---|
:e filename | Open a new file |
:w | Save the current file |
:q | Quit the current file |
:wq | Save and quit |
:bd | Close the current buffer |
:ls | List open buffers |
:bn | Next buffer |
:bp | Previous buffer |
Advanced Tips for Faster Editing
Enhance your editing efficiency with these shortcuts:
- Repeat Last Command: Press
.
in Normal Mode. - Macro Recording: Press
q
followed by a letter to record; press@
followed by the letter to execute. - Split Windows: Use
:split filename
or:vsplit filename
for side-by-side editing.
Conclusion
With this cheat sheet, you’ll improve your text-editing speed and accuracy in Vim. Keep it handy as a quick reference, and soon, navigating and editing in Vim will become second nature!