Vim Cheat Sheet

Vim is a modal text editor with distinct modes for different tasks.
Understanding these modes is key to using Vim effectively:
- Normal (default): For navigation, editing commands, and text manipulation.
- Insert: For typing and inserting text.
- Visual: For selecting text blocks.
- Command-line: For executing commands.
Start with Vim Tutor
Section titled “Start with Vim Tutor”For anyone completely new to Vim, the best place to start is Vim Tutor. It’s designed to be completed in about 30 minutes. By the time you’re done, you’ll know how to navigate, insert, delete, and save text.
To launch the tutor, just type this command in your terminal:
vimtutorVim basic operations
Section titled “Vim basic operations”A few essential commands to get you started.
Open a file in Vim:
vim <filename>Basic operations:
:h " Open the help documentation:w " Save changes:wq " Save and quit:q! " Quit without saving changesVim modes and movement
Section titled “Vim modes and movement”Insert mode
Section titled “Insert mode”These commands are used from Normal mode to enter Insert mode.
i " Insert text before the cursorI " Insert text at the beginning of the linea " Append text after the cursorA " Append text at the end of the lineo " Open a new line below the current one and insertO " Open a new line above the current one and insertBasic motions
Section titled “Basic motions”Navigate your text quickly and efficiently.
h " Move leftj " Move downk " Upl " Right0 " Move to the start of the line$ " Move to the end of the line^ " Move to the first non-blank character of the linegg " Go to the first line of the fileG " Go to the last line of the file5G " Go to line 5Word motions
Section titled “Word motions”Move between words and characters.
w " Move to the beginning of the next wordb " Move to the beginning of the previous worde " Move to the end of the current or next wordge " Move to the end of the previous word% " Jump between matching parentheses, braces, and bracketsVim editing and deleting
Section titled “Vim editing and deleting”Deleting
Section titled “Deleting”Delete text with these powerful commands.
x " Delete the character under the cursordd " Delete the current linedw " Delete from the cursor to the end of the wordD " Delete from the cursor to the end of the lineChanging
Section titled “Changing”Change commands delete and then put you into Insert mode.
r " Replace a single charactercw " Change the current wordC " Change to the end of the linecc " Change the entire lineUndo, redo, and repeating
Section titled “Undo, redo, and repeating”Manage your edits with these essential commands.
u " Undo the last changeCtrl+r " Redo the last undo. " Repeat the last change or commandCopy, cut, and paste
Section titled “Copy, cut, and paste”These operations are often referred to as “yanking” (copying), “deleting” (cutting), and “pasting.”
yy " Yank (copy) the current lineyw " Yank (copy) the current wordp " Paste after the cursorP " Paste before the cursorVim visual mode
Section titled “Vim visual mode”Use visual mode for selecting and operating on a block of text.
v " Start character-wise visual selectionV " Start line-wise visual selectionCtrl+v " Start block-wise visual selectiony " Yank (copy) the selected textd " Delete the selected textVim searching and replacing
Section titled “Vim searching and replacing”Find and replace text with power.
/word " Search forward for 'word'?word " Search backward for 'word'n " Go to the next matchN " Go to the previous match* " Search for the word under the cursor# " Search backwards for the word under the cursor
:%s/old/new/g " Find and replace all 'old' with 'new' in the file:%s/old/new/gc " Find and replace all with confirmationVim file navigation
Section titled “Vim file navigation”Vim has a built-in file explorer called Netrw to navigate your project without leaving the editor.
Open the file explorer:
:Explore " Open in the current window:Lexplore " Open in a new horizontal split (left):Vexplore " Open in a new vertical splitNavigate with these keys:
Enter " Open a directory or file- " Go up to the parent directoryu " Go back to the previous directory in historymb " Bookmark the current directorygb " Jump to a bookmarked directoryVim window management
Section titled “Vim window management”Split your screen to work on multiple files or sections of the same file.
:split " Horizontally split the window:vsplit " Vertically split the windowCtrl-w h " Move to the window to the leftCtrl-w j " Move to the window belowCtrl-w k " Move to the window aboveCtrl-w l " Move to the window to the rightCtrl-w q " Close the current split