Vim Cheatsheet
January 13, 2026 · 4 min read

Vim was initially released in January 1992.
If you have any questions, feel free to comment below. Click the block can copy the code.
And if you think it's helpful to you, just click on the ads which can support this site. Thanks!
Vim is a powerful command-line text editor that’s been around for decades, and it’s still widely used today. Whether you’re SSH-ing into a remote server or just prefer the keyboard-centric workflow, Vim is often the go-to choice. The learning curve can be steep at first — I remember the first time I opened Vim and couldn’t even figure out how to quit. But once you get the hang of it, the efficiency gains are real. This cheatsheet covers the essentials I use most often, and I’m trying to condense them.
Features #
- A command-line text editor.
- Automatically detects programming languages based on file extensions. Supports code indentation, syntax highlighting, and more.
- Usage: vim filename
- If the file exists, it opens it.
- If the file doesn’t exist, it creates a new file named filename.
Modes #
- Normal Mode: The default mode. Commands are entered like casting skills in a game — pressing different keys performs different operations. You can copy, paste, delete text, etc.
- Insert Mode
- Press
iin Normal Mode to enter Insert Mode. - Press
ESCto exit Insert Mode and return to Normal Mode.
- Press
- Command-Line Mode
- Press any of
:,/, or?in Normal Mode to enter Command-Line Mode. The command line appears at the bottom. - You can search, replace, save, quit, configure the editor, etc.
- Press any of
Command rules #
In VIM, many commands can be expanded into 3 parts:
- The first part is a number, representing the repeat count;
- The middle part is the command;
- The last part represents the object of the command.
examples #
- In 3de, 3 means execute 3 times, d is the delete command, e means from the current position to the end of the word. Delete 3 words forward from the current position.
- 3ce means delete 3 words forward from the current position, then enter insert mode.
n<Space>: n is a number, press the number then space, the cursor will move n characters to the right on the current linen<Enter>: n is a number, the cursor moves down n lines
Insert #
i: Enter insert modeI: Move cursor to the beginning of the line and enter insert modea: Move cursor one character to the right and enter insert modeA: Move cursor to the end of the line and enter insert modeu: UndoCtrl + r: RedoCtrl + q: Cancel the currently executing command when Vim is frozen
Command-Line Mode #
:wSave:w!Force save:qQuit:q!Force quit:wqSave and quit:saveas <path>Save as:set pasteEnable paste mode, disable auto-indent (prevents extra spaces from editor auto-indentation when pasting code):set nopasteDisable paste mode, enable auto-indent:set nuShow line numbers:set nonuHide line numbers:nohTurn off search highlight
Movement #
hor Left Arrow: ←jor Down Arrow: ↓kor Up Arrow: ↑lor Right Arrow: →gg: Move cursor to the first line (equivalent to1G)G: Move cursor to the last linegg=G: Format the entire file.ggdnG: gg jumps to the beginning, d means delete, nG means delete to line n.ggdG: Delete all content.
0: Move cursor to the beginning of the current line$: Move cursor to the end of the current line:nornG: Move cursor to line n (where n is a number)e: Move right to the next word (beginning of the next word)>: Indent selected text to the right once (press10>to indent 10 times)<: Indent selected text to the left onceCtrl+g: Display current line number and file infoCtrl+b: Scroll up one screenCtrl+f: Scroll down one screen
Search #
/word: Search for “word” below the cursor.?word: Search for “word” above the cursor.n: Repeat the previous search in the same direction.N: Repeat the previous search in the opposite direction.
Selection #
v: Select text
Delete #
d: Delete selected textdd: Delete current line
Copy and Paste #
y: Copy (yank) selected textyy: Copy current linep: Paste copied content on the next line (for copied lines) or at the next position (for copied text)
Exception Handling #
Every time you edit a file with vim, it automatically creates a temporary file named .filename.swp. If you try to open a file when its swp file already exists, you’ll get an error. This is because two processes could have read/write conflicts.
There are two ways to resolve this:
- Find the program that currently has the file open and close it. This prevents read/write conflicts.
- Simply delete the
swpfile directly.
Examples #
:n1,n2s/word1/word2/g: n1 and n2 are line numbers. Search for word1 between line n1 and n2, and replace it with word2:1,$s/word1/word2/g: Replace all occurrences of word1 with word2 in the entire file:1,$s/word1/word2/gc: Replace all occurrences of word1 with word2 in the entire file, with confirmation prompt before each replacement
Related readings
If you want to follow my updates, or have a coffee chat with me, feel free to connect with me: