Skip to main content

Vim Command Cheatsheet

Vim is synonymous with efficient text editing. This cheatsheet covers the most commonly used Vim commands — from basic operations to macro recording — each with practical examples. Whether you're new to Vim or looking to level up, this guide has you covered. Start with basic operations and cursor movement, then gradually explore search, windows, and advanced features.

Updated: 2026-07-16·42 commands

Quick Reference

TaskKey / Command
Start editingi (insert before cursor)
Save file:w
Save and quit:wq or ZZ
Copy a lineyy
Delete a linedd
Pastep (after) / P (before)
Undou
Search/pattern
Replace all:%s/old/new/g
Split window:vs (vertical) / :sp (horizontal)

Basic Operations

``bash # Mode switching i # Insert before cursor a # Insert after cursor o # Open new line below and insert I # Insert at line beginning A # Insert at line end O # Open new line above and insert Esc / Ctrl+[ # Return to normal mode

# File operations :e file.txt # Open a file :w # Save :q # Quit :wq / ZZ # Save and quit :q! # Force quit (discard changes) :e! # Reload file (undo all changes) :help topic # Open help `

Cursor Movement

`bash # Basic movement h # Left j # Down k # Up l # Right 5j # Move down 5 lines

# Word movement w # Forward to word start b # Backward to word start e # Forward to word end ge # Backward to word end 3w # Forward 3 words

# Line movement 0 # First column ^ # First non-blank character $ # End of line g_ # Last non-blank character

# File navigation gg # First line G # Last line 42G / :42 # Jump to line 42 Ctrl+d # Scroll down half page Ctrl+u # Scroll up half page Ctrl+f # Scroll down full page Ctrl+b # Scroll up full page

# Code blocks % # Matching bracket ( / ) # Previous/next sentence { / } # Previous/next paragraph

# Screen positioning zz # Center cursor on screen zt # Top of screen zb # Bottom of screen `

Editing

`bash # Delete x # Delete character under cursor X # Delete character before cursor 3x # Delete 3 characters dd # Delete current line 5dd # Delete 5 lines D # Delete to end of line dw # Delete to word end diw # Delete inner word daw # Delete a word (including space) di( # Delete inside parentheses da" # Delete around quotes

# Yank (Copy) yy # Yank current line 5yy # Yank 5 lines yiw # Yank inner word y$ # Yank to end of line

# Paste p # Paste after cursor P # Paste before cursor

# Change r # Replace character R # Enter replace mode ciw # Change inner word ci( # Change inside parentheses c$ # Change to end of line cc # Change entire line

# Undo & Repeat u # Undo Ctrl+r # Redo . # Repeat last change `

Visual Mode

`bash # Enter visual mode v # Character-wise visual V # Line-wise visual Ctrl+v # Block visual (column editing)

# Visual operations (select then press) d # Delete selection y # Yank (copy) selection > # Indent right < # Indent left ~ # Toggle case u # Lowercase U # Uppercase : # Execute command on selection

# Column editing trick Ctrl+v # Enter block select jjj # Select multiple lines downwards I # Insert at column start text # Type the text to insert Esc # Apply to all selected lines `

Search & Replace

`bash # Search /pattern # Search forward ?pattern # Search backward n # Next match N # Previous match * # Search word under cursor (forward) # # Search word under cursor (backward)

# Highlight control :nohlsearch # Clear search highlighting set hlsearch # Enable highlight set nohlsearch # Disable highlight

# Replace :s/old/new/ # Replace first match on current line :s/old/new/g # Replace all on current line :%s/old/new/g # Replace in whole file :%s/old/new/gc # Replace with confirmation :5,20s/old/new/g # Replace in lines 5-20 :%s/old/new/gn # Count matches (no actual replace) `

Windows & Tabs

`bash # Window management :sp [file] # Split horizontally :vs [file] # Split vertically Ctrl+w h # Go to left window Ctrl+w j # Go to window below Ctrl+w k # Go to window above Ctrl+w l # Go to right window Ctrl+w w # Cycle through windows Ctrl+w = # Equalize window sizes Ctrl+w _ # Maximize window height Ctrl+w | # Maximize window width Ctrl+w + # Increase height Ctrl+w - # Decrease height :q # Close current window :only # Close all but current

# Tab pages :tabnew [file] # Open in new tab gt # Next tab gT # Previous tab Ngt # Go to tab N :tabclose # Close current tab :tabonly # Close other tabs :tabmove +1 # Move tab right `

Advanced Techniques

`bash # Macros qa # Start recording macro 'a' ... # Perform your actions q # Stop recording @a # Play macro 'a' @@ # Repeat last macro 5@a # Play macro 'a' 5 times

# Registers "ayy # Yank current line to register 'a' "ap # Paste from register 'a' :reg # View all registers "+y # Yank to system clipboard "+p # Paste from system clipboard

# Marks ma # Set mark 'a' at cursor a # Jump to mark 'a' 'a # Jump to line of mark 'a' :marks # List all marks

# Autocomplete (insert mode) Ctrl+p # Previous completion Ctrl+n # Next completion Ctrl+x Ctrl+l # Complete whole line Ctrl+x Ctrl+f # Complete filename Ctrl+x Ctrl+] # Complete tag

# Run shell commands from Vim :!ls # Run 'ls' command :!python % # Run current Python file :read !date # Insert command output :r !curl -s URL # Insert curl result ``

Vim Configuration

`vim " ~/.vimrc common settings

" Interface set number " Show line numbers set relativenumber " Show relative line numbers set cursorline " Highlight current line set showmode " Show current mode set showcmd " Show partial commands

" Indentation set tabstop=4 " Tab width: 4 set shiftwidth=4 " Indent width: 4 set expandtab " Use spaces instead of tabs set autoindent " Auto indent set smartindent " Smart indent

" Search set hlsearch " Highlight search results set incsearch " Incremental search set ignorecase " Ignore case set smartcase " Smart case sensitivity

" Editing set backspace=indent,eol,start " Allow backspace over anything set clipboard=unnamedplus " Use system clipboard syntax on " Enable syntax highlighting

" File type filetype plugin indent on " Load filetype-specific plugins `

Vim Learning Path

` Beginner → Basic operations + cursor movement (hjkl + counts) Daily use → Delete/yank/paste + search/replace + undo/redo Efficiency → Text objects (diw/ci(/da") + block visual mode Advanced → Macros + registers + multi-file editing + customization ``

Basic(9)

CommandLevel
i / a / o
Enter insert mode (before cursor / after cursor / new line)
Basic
Esc / Ctrl+[
Return to normal mode
Basic
:w
Save the file
Basic
:q
Quit Vim
Basic
:wq / ZZ
Save and quit
Basic
:q!
Force quit (discard changes)
Basic
:e <file>
Open a file
Basic
:help <topic>
Open Vim built-in help
Intermediate
vimtutor
Launch the Vim interactive tutorial (best way for beginners)
Basic

editing(7)

CommandLevel
x / X
Delete character under cursor / before cursor
Basic
dd / yy / p / P
Delete line / yank line / paste after / paste before
Basic
diw / ciw / yiw
Delete / change / yank inner word
Intermediate
da" / ci( / ya{
Delete / change / yank around quotes/brackets (including delimiters)
Intermediate
r<char>
Replace character under cursor
Basic
. (dot)
Repeat the last change
Intermediate
u / Ctrl+r
Undo / redo
Basic

Visual Mode(3)

CommandLevel
v / V / Ctrl+v
Character-wise / line-wise / block-wise visual mode
Intermediate
> / <
Indent / unindent selected lines
Basic
~ / u / U
Toggle case / lowercase / uppercase
Basic

Windows(5)

CommandLevel
:sp <file> / :vs <file>
Split horizontally / vertically to open a file
Intermediate
Ctrl+w h/j/k/l
Navigate to left / down / up / right window
Intermediate
Ctrl+w = / _ / |
Equalize windows / maximize height / maximize width
Intermediate
:tabnew / gt / gT
New tab / next tab / previous tab
Intermediate
:tabm <n>
Move the current tab page to position N
Intermediate

Advanced(6)

CommandLevel
q<letter> ... q
Start recording a macro / stop recording
Expert
@<letter> / @@
Play a macro / repeat last macro
Expert
"<reg>p / "<reg>y
Paste / yank using a specific register
Expert
m<letter> / '<letter>
Set a mark / jump to a mark
Intermediate
:!<command>
Execute a shell command from Vim
Intermediate
Ctrl+p / Ctrl+n
Autocomplete in insert mode (previous / next)
Intermediate

FAQ

This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-16.