Vim Cheatsheet

Commands for Beginners and Advanced Users

posted by Pfp of vladSink

updated
Blog post featured image

Vim 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:

CommandDescription
h, j, k, lMove left, down, up, and right
0Go to the beginning of the line
$Move to the end of the line
wJump to the start of the next word
bJump to the start of the previous word
ggGo to the top of the file
GGo to the bottom of the file
Ctrl + uScroll up by half a screen
Ctrl + dScroll down by half a screen

Inserting Text

Switch to Insert Mode to add text:

CommandDescription
iInsert before the cursor
IInsert at the start of the line
aAppend after the cursor
AAppend at the end of the line
oOpen a new line below the cursor
OOpen a new line above the cursor

Editing and Deleting Text

Modify text quickly with these commands:

CommandDescription
xDelete the character under the cursor
dwDelete to the start of the next word
d$Delete to the end of the line
ddDelete the entire line
uUndo the last action
Ctrl + rRedo the last undone change
yyCopy (yank) the entire line
pPaste below the cursor
PPaste above the cursor

Copying and Pasting from Outside Neovim

To copy and paste between Neovim and your system clipboard, use:

CommandDescription
"+yCopy selected text to the system clipboard
"+pPaste text from the system clipboard

Text Selection in Visual Mode

Select text by entering Visual Mode:

CommandDescription
vStart character-by-character selection
VStart line selection
Ctrl + vStart block selection

Searching and Replacing Text

Find and replace text efficiently:

CommandDescription
/textSearch forward for text
?textSearch backward for text
nNext search match
NPrevious search match
:%s/old/new/gReplace all old with new
:s/old/new/gReplace in the current line

Working with Multiple Files and Buffers

Manage multiple files with these commands:

CommandDescription
:e filenameOpen a new file
:wSave the current file
:qQuit the current file
:wqSave and quit
:bdClose the current buffer
:lsList open buffers
:bnNext buffer
:bpPrevious 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!


Comments

LogIn to leave a comment