Vim Cheat Sheet
Vim from the first :wq to macros, text objects, :global and a vimrc that fits, with Neovim's init.lua next to it. Every key on the page was checked against Vim 9.2's own help, and the search and replace examples show the real result of running them in Vim.
By Bogdan SanduUpdated December 2, 2026Checked against Vim 9.2
Vim command explainer
Type a Normal mode command such as d3w, ci", "+yy or gUiw, or an Ex command such as :%s/old/new/gc, and read what it does piece by piece.
Try: ct), yi{, >ip, 5x, 2gUU, @q, :g/TODO/d, :10,20s/\s\+$//e
vimrc builder
Choose the behaviour you want and copy a vimrc for Vim, or an init.lua for Neovim. With persistent undo in Vim, create the folder once with mkdir -p ~/.vim/undo.
Start, Save & Quit
Vim has modes: Normal mode for moving and editing with keys, Insert mode for typing text, Visual mode for selecting and Command-line mode for commands that start with a colon. Esc always takes you back to Normal mode.
Get out, and save
How to exit Vim
If keys type text instead of running commands, press Esc first. In Vim 9.2, :Tutor starts the interactive tutorial; vimtutor in the shell works in every version.
| Keys | Does |
|---|---|
:w | Save |
:q | Quit; refuses if there are unsaved changes |
:wq or :x | Save and quit; :x only writes if something changed |
ZZ | Same as :x, from Normal mode |
:q! | Quit and throw away changes |
ZQ | Same as :q! |
:wa and :qa | Save all, quit all |
:w !sudo tee % | Save a file you opened without permission to write it |
Open Vim
From the shell
$ vim file.txt # open a file
$ vim +42 file.txt # open at line 42
$ vim +/TODO file.txt # open at the first TODO
$ vim -O a.py b.py # two files side by side
$ vim -d old.txt new.txt # diff mode
$ vim -R log.txt # read-onlyFiles from inside Vim
| Command | Does |
|---|---|
:e path | Edit another file |
:e! | Reload the file, dropping changes |
:w newname | Save a copy under another name |
:saveas newname | Save under another name and keep editing it |
:r file | Insert another file below the cursor |
:r !date | Insert the output of a shell command |
Modes
Switch modes
Enter Insert mode
| Keys | Starts inserting |
|---|---|
i and a | Before and after the cursor |
I and A | At the first non-blank character and at the end of the line |
o and O | On a new line below and above |
s | Delete the character and insert |
S or cc | Clear the line and insert |
C | Delete to the end of the line and insert |
gi | Where you last left Insert mode |
Other modes
| Keys | Mode |
|---|---|
Esc or Ctrl+[ | Back to Normal mode |
v | Visual, characters |
V | Visual, whole lines |
Ctrl+v | Visual block, a rectangle |
R | Replace: typing overwrites |
: | Command-line mode |
Ctrl+o in Insert mode | Run one Normal mode command, then return |
Motions
Basic movement
Characters, words and lines
A count repeats a motion: 5j moves five lines down and 3w three words forward. w stops at punctuation, W does not.
| Keys | Moves to |
|---|---|
h j k l | Left, down, up, right |
w and b | Next word start, previous word start |
e and ge | End of word, end of the previous word |
W B E | The same, for words separated only by spaces |
0 | First column of the line |
^ | First non-blank character |
$ | End of the line |
gg and G | First and last line |
42G or :42 | Line 42 |
50% | Halfway through the file |
Bigger jumps
Screen and paragraph
| Keys | Moves to |
|---|---|
} and { | Next and previous paragraph |
% | The matching bracket |
H M L | Top, middle and bottom of the screen |
Ctrl+d and Ctrl+u | Half a page down and up |
Ctrl+f and Ctrl+b | A page down and up |
zz zt zb | Scroll so the cursor line is in the middle, top or bottom |
Find a character on the line
| Keys | Does |
|---|---|
fx and Fx | Jump to the next or previous x |
tx and Tx | Jump to just before the next or previous x |
; and , | Repeat the last f, t, F or T forward or backward |
Jumps and marks
Go back to where you were
Lowercase marks belong to one file; uppercase marks such as mA work across files.
| Keys | Does |
|---|---|
Ctrl+o and Ctrl+i | Back and forward through the jump list |
` . `` | Position of the last change |
gi | Last insert position, in Insert mode |
ma | Set mark a |
` a ` and 'a` | Jump to mark a, or to its line |
:marks | List marks |
gd | Go to the local definition of the word under the cursor |
gf | Open the file whose name is under the cursor |
Search
Search in a file
Find text
| Keys | Does |
|---|---|
/text | Search forward |
?text | Search backward |
n and N | Next and previous match |
* and # | Search for the word under the cursor, forward or backward |
:noh | Clear the search highlight |
/\cword | Ignore case for this search |
/\vfoo|bar | Very magic: regex characters work without backslashes |
Settings that make search pleasant
smartcase ignores case until you type a capital letter. incsearch shows matches while you type.
set hlsearch incsearch
set ignorecase smartcase
nnoremap <silent> <Esc><Esc> :nohlsearch<CR>Search across files
vimgrep and the quickfix list
vimgrep fills the quickfix list; :copen shows it and Enter jumps to an entry. :grep uses an external program set by 'grepprg', which can be ripgrep: set grepprg=rg\ --vimgrep.
:vimgrep /TODO/ **/*.py
:copen
:cnext
:cprev
:grep -r "TODO" .Operators & Text Objects
Vim edits are sentences: an operator (verb) followed by a motion or text object (noun). d + w deletes a word, c + i" changes the text inside quotes, y + ap copies a paragraph. Learn a few of each and they combine into hundreds of commands.
Operators
Verbs
Doubling an operator acts on the whole line: dd, cc, yy, >>, gUU. A count applies too: 3dd deletes three lines.
| Operator | Does |
|---|---|
d | Delete, into a register |
c | Change: delete, then Insert mode |
y | Yank, which means copy |
> and < | Indent and unindent |
= | Auto-indent |
gu gU g~ | Lowercase, uppercase, toggle case |
gq | Format text to 'textwidth' |
! | Filter through a shell command |
Text objects
Nouns that work with any operator
| Object | Selects |
|---|---|
iw and aw | Inner word; a word plus the space after it |
is and as | Sentence |
ip and ap | Paragraph |
i" and a" | Inside quotes; including the quotes |
i( or ib, a( | Inside parentheses; including them |
i{ or iB, a{ | Inside braces |
i[ and i< | Inside brackets and angle brackets |
it and at | Inside an HTML or XML tag; including the tag |
Combinations you will use daily
Text objects work from anywhere inside the object, so ci" works no matter where the cursor is between the quotes.
| Keys | Does |
|---|---|
ciw | Change the word under the cursor |
ci" | Change the text inside the quotes |
di( | Delete the arguments of a function call |
da{ | Delete a block including its braces |
yap | Copy a paragraph |
cit | Change the content of an HTML tag |
dt, | Delete up to the next comma |
gUiw | Uppercase the word |
>ip | Indent a paragraph |
=G | Re-indent to the end of the file |
Basic Editing
Small edits
Characters and lines
| Keys | Does |
|---|---|
x and X | Delete the character under and before the cursor |
r then a character | Replace one character |
~ | Toggle the case of the character |
J | Join the next line onto this one, with a space |
gJ | Join without adding a space |
dd and D | Delete the line; delete to the end of the line |
Ctrl+a and Ctrl+x | Add to or subtract from the number under the cursor |
xp | Swap two characters |
ddp | Swap two lines |
Undo and repeat
The most useful key in Vim
Make an edit once, then press . at each spot that needs the same change. Combined with n, it replaces many search-and-replace jobs: /foo, cgnbar then . . ..
| Keys | Does |
|---|---|
u | Undo |
Ctrl+r | Redo |
U | Undo every change on the last changed line |
. | Repeat the last change |
g- and g+ | Move back and forward in time through the undo tree |
:earlier 10m | Go back to the file as it was ten minutes ago |
Keep undo history after closing a file
Create the directory first with mkdir -p ~/.vim/undo. Neovim keeps persistent undo in its state directory without the undodir line.
set undofile
set undodir=~/.vim/undo//Copy, Paste & Registers
Paste
Yank and put
Deleting also fills the unnamed register, so p after dd pastes the deleted line. Register 0 keeps only yanks, which fixes the classic "my copy got replaced" problem.
| Keys | Does |
|---|---|
yy or Y | Copy the line |
yiw | Copy the word |
p and P | Paste after and before the cursor |
gp | Paste and move the cursor after the pasted text |
]p | Paste with the indent of the current line |
"0p | Paste the last yank, even after deleting something |
Registers
Named registers and the system clipboard
| Register | Holds |
|---|---|
"ayy and "ap | Yank into register a, put from it |
"Ayy | Append to register a |
"+y and "+p | The system clipboard |
"*y | The primary selection on X11, the clipboard elsewhere |
"_d | The black hole register: delete without saving it |
". | The last inserted text |
"% | The current file name |
": | The last command line |
:reg | Show every register |
Ctrl+r a in Insert mode | Insert register a |
Use the system clipboard by default
This needs a Vim built with clipboard support; check vim --version | grep clipboard for +clipboard. Neovim uses a provider such as wl-copy, xclip or pbcopy, and Vim 9.2 added Wayland clipboard support.
set clipboard=unnamedplusVisual Mode
Select, then act
Visual mode keys
| Keys | Does |
|---|---|
v, V, Ctrl+v | Select characters, lines or a block |
o | Move to the other end of the selection |
gv | Select the previous selection again |
vi" and vap | Select a text object |
d, y, c, >, <, ~ | Act on the selection |
u and U | Lowercase and uppercase the selection |
J | Join the selected lines |
: | Run an Ex command on the selected lines |
Edit many lines at once with a block
| Keys | Does |
|---|---|
Ctrl+v, move down, I, type, Esc | Insert the same text at the start of every line |
Ctrl+v, move down, $A, type, Esc | Append text to the end of every line |
Ctrl+v, select, c, type, Esc | Replace a column on every line |
Ctrl+v, select numbers, g Ctrl+a | Turn the numbers into a sequence 1, 2, 3 |
Search & Replace
:substitute
Replace in the whole file
% is the range for every line and g replaces every match on a line, not just the first.
:%s/colour/color/gThe color of the color wheel.
Another color.Whole words only, and capture groups
\< and \> mark word boundaries, so idx and valid stay. The second command works on line 2 only; with \v, very magic, groups need no backslashes and \1 and \2 put them back in a new order.
:%s/\<id\>/user_id/g
:2s/\v(\w+), (\w+)/\2 \1/user_id, idx, valid user_id
Ada LovelaceFlags and ranges
| Command | Does |
|---|---|
:s/a/b/ | First match on the current line |
:%s/a/b/gc | Every match, asking for confirmation |
:%s/a/b/gi | Ignore case |
:10,20s/a/b/g | Lines 10 to 20 |
:'<,'>s/a/b/g | The visual selection, which : fills in for you |
:%s/a/b/gn | Only count the matches |
:%s//new/g | Reuse the last search pattern |
:cfdo %s/a/b/g | update | Every file in the quickfix list |
Change case in the replacement
\u uppercases the next character and \L lowercases everything after it, so this turns every word into title case.
:%s/\v<(\w)(\w*)>/\u\1\L\2/gHello World From Vim:global & Ex Commands
:global
Delete, keep or move matching lines
:g/pattern/cmd runs a command on every matching line; :v does it on every line that does not match. Here the first removes blank lines and the second keeps only warnings and errors.
:g/^\s*$/d
:v/ERROR\|WARN/dWARN slow
ERROR failedRun Normal mode keys on many lines
:norm types keys as if you were in Normal mode on each line. Here A appends a semicolon to every line, then 0cw changes the first word of each line that starts with let.
:%norm A;
:g/^let/norm 0cwconstconst a = 1;
const b = 2;
const c = 3;Lines as a whole
Sort, dedupe, move and copy
:sort u sorts and removes duplicate lines; :sort n sorts by number and :sort! reverses. :1m$ moves line 1 to the end; :t copies instead of moving.
:sort u
:1m$banana
pear
appleEx commands worth knowing
| Command | Does |
|---|---|
:5,10d | Delete lines 5 to 10 |
:.,+3y | Yank this line and the next three |
:t. | Duplicate the current line |
:m+1 and :m-2 | Move the line down or up |
:%!jq . | Filter the whole file through a command |
:.!date | Replace the line with a command's output |
:retab | Convert tabs to spaces using the current settings |
:%s/\s\+$//e | Remove trailing whitespace |
Macros
Record and replay
Record a macro
Start a macro with a motion that puts the cursor in a known place, such as 0 or ^, and end it by moving to the next line, so it can run many times in a row.
| Keys | Does |
|---|---|
qa | Start recording into register a |
q | Stop recording |
@a | Run the macro |
@@ | Run the last macro again |
10@a | Run it ten times |
:'<,'>norm @a | Run it on every selected line |
"ap and "ay$ | Paste the macro to edit it, then yank it back |
A macro, run from the command line
This sets register a to the keys I, dash, space, Esc, j, jumps to the first line with gg and runs the macro three times: a bulleted list in one command.
:let @a = "I- \<Esc>j"
:exe "normal gg3@a"- milk
- eggs
- breadWindows, Buffers & Tabs
Buffers
Every open file is a buffer
| Command | Does |
|---|---|
:ls | List buffers |
:b 3 or :b name | Switch to buffer 3, or one whose name contains name |
:bn and :bp | Next and previous buffer |
Ctrl+^ | The alternate buffer, the one you were in before |
:bd | Close the buffer |
:set hidden | Switch buffers without saving first; on by default in Neovim, off in Vim |
Windows
Split the screen
| Keys | Does |
|---|---|
:sp file and Ctrl+w s | Split horizontally |
:vs file and Ctrl+w v | Split vertically |
Ctrl+w h j k l | Move to the window left, below, above, right |
Ctrl+w w | Next window |
Ctrl+w q and Ctrl+w c | Close the window |
Ctrl+w o or :only | Close every other window |
Ctrl+w = | Make all windows the same size |
Ctrl+w _ and Ctrl+w | | Maximise the height or width |
Ctrl+w + - < > | Grow or shrink by one line or column |
Ctrl+w H J K L | Move the window to the far left, bottom, top or right |
Tabs
Tab pages hold window layouts
In Vim a tab is a layout of windows, not one file. Most people work with buffers and splits and use tabs for separate tasks.
| Keys | Does |
|---|---|
:tabnew file | Open a file in a new tab |
gt and gT | Next and previous tab |
3gt | Tab 3 |
:tabclose | Close the tab |
Ctrl+w T | Move the current window into a new tab |
vim -p a b c | Open files in tabs from the shell |
File Explorer & Terminal
Browse and run
Built-in file explorer
| Command | Does |
|---|---|
:Ex | Explore the current file's directory |
:Vex and :Sex | Explore in a vertical or horizontal split |
- in netrw | Up one directory |
% and d in netrw | New file, new directory |
D and R in netrw | Delete and rename |
A terminal inside Vim
| Command | Does |
|---|---|
:term | Open a terminal in a split |
:vert term | In a vertical split |
Ctrl+w N | Terminal-Normal mode in Vim, to scroll and copy |
Ctrl+\ Ctrl+n | Terminal-Normal mode, in Vim and Neovim |
:!cmd | Run a shell command and show its output |
Folding
Fold code
Open and close folds
| Keys | Does |
|---|---|
za | Toggle the fold under the cursor |
zo and zc | Open and close a fold |
zR and zM | Open all folds, close all folds |
zf then a motion | Create a fold, with foldmethod=manual |
zj and zk | Move to the next and previous fold |
Pick how folds are made
foldlevelstart=99 opens files with every fold open. Other methods are syntax, marker for {{{ and }}} comments, and expr; Neovim with Tree-sitter uses foldexpr=v:lua.vim.treesitter.foldexpr().
set foldmethod=indent
set foldlevelstart=99Insert Mode & Completion
Keys while typing
Edit without leaving Insert mode
| Keys | Does |
|---|---|
Ctrl+w | Delete the word before the cursor |
Ctrl+u | Delete back to the start of the line |
Ctrl+t and Ctrl+d | Indent and unindent the line |
Ctrl+r then a register | Insert a register, Ctrl+r + for the clipboard |
Ctrl+o then a command | Run one Normal mode command |
Ctrl+v then a key | Insert the key literally, such as a Tab |
Completion
Vim 9.2 can also complete as you type: set 'autocomplete', and add fuzzy to 'completeopt' for fuzzy matching.
| Keys | Completes |
|---|---|
Ctrl+n and Ctrl+p | Words from open buffers |
Ctrl+x Ctrl+f | File names |
Ctrl+x Ctrl+l | Whole lines |
Ctrl+x Ctrl+o | Omni completion from the filetype or a language server |
Ctrl+x Ctrl+r | Words from registers (Vim 9.2) |
Ctrl+x s | Spelling suggestions |
vimrc Essentials
A starter vimrc
Settings most people want
Vim 9.2 also reads ~/.config/vim/vimrc, following the XDG layout. Reload with :source $MYVIMRC after an edit.
set nocompatible
filetype plugin indent on
syntax on
set number relativenumber
set expandtab tabstop=4 shiftwidth=4 softtabstop=4
set autoindent
set hidden
set incsearch hlsearch ignorecase smartcase
set scrolloff=5
set mouse=a
set clipboard=unnamedplus
set undofile
let mapleader = " "
nnoremap <leader>w :w<CR>
nnoremap <leader>q :q<CR>Mappings
Always use the noremap forms so your mapping is not expanded by other mappings. <leader> is the key you set in mapleader, often Space.
| Command | Mode |
|---|---|
nnoremap | Normal |
inoremap | Insert |
vnoremap and xnoremap | Visual; xnoremap leaves out Select mode |
onoremap | Operator-pending, for custom text objects |
cnoremap | Command-line |
tnoremap | Terminal |
:map and :verbose nmap <leader>w | List mappings, and where one was set |
Settings per file type
The augroup with autocmd! clears the group first, so reloading the vimrc does not add the same autocommands twice.
augroup filetypes
autocmd!
autocmd FileType python setlocal shiftwidth=4 textwidth=88
autocmd FileType javascript,typescript,html,css setlocal shiftwidth=2
autocmd BufWritePre *.py,*.js %s/\s\+$//e
augroup ENDCheck and change a setting
| Command | Does |
|---|---|
:set tabstop? | Show the value |
:set number! | Toggle a boolean setting |
:setlocal spell | Only for the current buffer |
:verbose set tabstop? | Show where it was last set |
:options | Browse every option |
Neovim & init.lua
init.lua
The same starter config in Lua
Neovim keeps most Vim keys and Ex commands, so everything above works in it too. :checkhealth reports missing providers, clipboard tools and broken plugins.
vim.g.mapleader = " "
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.expandtab = true
vim.opt.shiftwidth = 4
vim.opt.ignorecase = true
vim.opt.smartcase = true
vim.opt.clipboard = "unnamedplus"
vim.opt.undofile = true
vim.keymap.set("n", "<leader>w", "<cmd>w<cr>", { desc = "Save" })
vim.api.nvim_create_autocmd("TextYankPost", {
callback = function() vim.hl.on_yank() end,
})Plugins with vim.pack
Neovim 0.12 includes vim.pack, a built-in plugin manager. lazy.nvim remains the most popular third-party one.
vim.pack.add({
"https://github.com/neovim/nvim-lspconfig",
"https://github.com/nvim-treesitter/nvim-treesitter",
})Language servers
With nvim-lspconfig installed for the server definitions, vim.lsp.enable starts each server for its file types. Default keys then include K for hover, grn to rename, gra for code actions and grr for references.
vim.lsp.enable({ "lua_ls", "pyright", "ts_ls" })Plugins in Vim
Install plugins
Native packages, no manager needed
Everything in pack/*/start loads at startup; put plugins in pack/*/opt and load them with :packadd name. Vim 9.2 ships optional packages such as comment, hlyank and nohlsearch: :packadd comment.
$ mkdir -p ~/.vim/pack/plugins/start
$ git clone https://github.com/tpope/vim-surround ~/.vim/pack/plugins/start/vim-surroundvim-plug
Run :PlugInstall after adding plugins and :PlugUpdate to update them.
call plug#begin()
Plug 'tpope/vim-surround'
Plug 'tpope/vim-fugitive'
Plug 'junegunn/fzf.vim'
call plug#end()Plugins worth knowing
| Plugin | For |
|---|---|
| vim-surround | cs"' changes quotes, ysiw) wraps a word in parentheses |
| vim-fugitive | Git inside Vim: :Git, :Git blame, :Gdiffsplit |
| fzf.vim | Fuzzy find files, buffers and text |
| vim-commentary | gcc comments a line; built into Vim 9.2 as the comment package and into Neovim |
| ALE or coc.nvim | Linting and language servers in Vim |
Help, Spell & Diff
Help
Read Vim's own documentation
| Command | Opens |
|---|---|
:help | The main help page |
:help ciw | Help for a key or command |
:help i_CTRL-W | A key in Insert mode; v_ for Visual, c_ for Command-line |
:help 'tabstop' | An option, in quotes |
:helpgrep word | Search all help text |
Ctrl+] and Ctrl+o | Follow a link, go back |
Spell check
Check spelling as you type
| Keys | Does |
|---|---|
:set spell spelllang=en_us | Turn on spell checking |
]s and [s | Next and previous misspelled word |
z= | Suggestions for the word |
zg | Add the word to your dictionary |
Diff
Compare files
| Keys | Does |
|---|---|
vim -d a b or vimdiff a b | Open in diff mode |
]c and [c | Next and previous change |
do | Get the change from the other file |
dp | Put this change into the other file |
:diffupdate | Recompute the diff |
Errors & Gotchas
Common messages
What they mean
| Message or symptom | Means | Fix |
|---|---|---|
E37: No write since last change | Unsaved changes | :w, or :q! to discard |
E45: 'readonly' option is set | Opened read-only | :w!, or :w !sudo tee % for system files |
E325: ATTENTION swap file found | Vim crashed, or the file is open elsewhere | Press r to recover, then delete the .swp file |
recording @q in the status line | You pressed q by accident | Press q again to stop |
| The screen froze | Ctrl+S paused the terminal | Press Ctrl+Q |
| Typing runs commands | You are in Normal mode | Press i to insert |
| Pasted code is indented more and more | Auto-indent ran on the paste | Use "+p, or :set paste before pasting in terminal Vim |
Vim 9 & Neovim Versions
Release history
Recent releases
Check your version with vim --version or nvim --version. Distribution packages often lag: Ubuntu 24.04 ships Vim 9.1.
| Release | Date | Highlights |
|---|---|---|
| Vim 9.2 | February 14, 2026 | Autocompletion, Wayland clipboard, XDG config path, vertical tabpanel, :Tutor, Vim9 enums, generics and tuples |
| Vim 9.1 | January 2, 2024 | Vim9 classes and objects, smooth scrolling, virtual text |
| Neovim 0.12 | March 29, 2026 | Built-in vim.pack plugin manager; 0.12.7 is the current patch release |
| Neovim 0.11 | 2025 | vim.lsp.enable and vim.lsp.config, default LSP mappings |
Nothing matches. Try a single word.
What Is a Vim Cheat Sheet
A Vim cheat sheet is a quick reference to the keys and commands of Vim, the modal text editor, grouped so you can find the key for a motion, the syntax of a substitution or the setting for your vimrc without opening the help. People also search for Vim commands, Vim shortcuts or a vi cheat sheet; they usually need it while learning the editor, editing a config file on a server or bringing Vim keys into another editor.
This one has 21 sections and 57 rows, written for Vim 9.2 and Neovim 0.12. A script looked up every key in the tables in Vim 9.2's own help, so a key that does not exist or behaves differently would have been caught. The search and replace, :global, :norm and macro examples were run in Vim on the sample text shown, and the result under them is what Vim produced.
How It Differs From vimtutor and :help
vimtutor teaches the first hour and :help documents everything, with more than a hundred files. This page sits between them: it groups the keys by what you are trying to do, shows the combinations people actually use, such as ciw, ci" and :g/^$/d, and explains the reason behind each one, so the commands stick instead of being memorised one by one.
What This Vim Cheat Sheet Covers
- Start: opening, saving and quitting and modes.
- Moving: motions, jumps and marks and search.
- Editing: operators and text objects, basic editing and undo, registers and the clipboard, Visual mode, search and replace, :global and Ex commands and macros.
- Workspace: windows, buffers and tabs, the file explorer and terminal, folding and Insert mode and completion.
- Configuration: vimrc essentials, Neovim and init.lua and plugins.
- Help: help, spell check and diff, common messages and release history.
Vim Commands Quick Reference
| Task | Keys |
|---|---|
| Save and quit | :wq or ZZ |
| Quit without saving | :q! |
| Insert, append | i, a, A |
| New line below | o |
| Back to Normal mode | Esc |
| Next word, previous word | w, b |
| Start, end of line | 0, $ |
| First, last line | gg, G |
| Go to line 42 | 42G or :42 |
| Delete a line | dd |
| Change a word | ciw |
| Change inside quotes | ci" |
| Copy a line, paste | yy, p |
| Undo, redo | u, Ctrl+r |
| Repeat the last change | . |
| Search | /text, then n |
| Replace everywhere | :%s/old/new/g |
| Delete blank lines | :g/^$/d |
| Select lines | V |
| Indent a block | >ip |
| Record, run a macro | qa ... q, @a |
| Split vertically | :vs file |
| Next window | Ctrl+w w |
| System clipboard | "+y, "+p |
What Vim Is
Vim is a modal text editor: keys mean different things in Normal, Insert, Visual and Command-line mode, so in Normal mode every letter is a command and you rarely need a modifier key. Bram Moolenaar released it in 1991 as Vi IMproved, an extended clone of Bill Joy's vi from 1976, and maintained it until his death in 2023; a team of long-time contributors has released Vim 9.1 and Vim 9.2 since. Neovim, started in 2014 as a fork, focuses on Lua configuration, a built-in language server client and an API for embedding. Both are free and open source; Vim is distributed from vim.org and Neovim from neovim.io.
The idea that makes Vim fast is composable editing: an operator such as d, c or y combines with any motion or text object, so learning one new motion gives you a new delete, change and copy at once. Combined with the dot command and macros, repetitive edits become a few keystrokes.
Where Vim Fits Today
Vim or a compatible vi is installed on almost every Linux server, container image and Mac, which makes it the editor you can count on over SSH, together with tmux and the Linux command line. Its keys also live inside graphical editors through plugins: VSCodeVim for VS Code, IdeaVim for JetBrains IDEs and the built-in Vim mode in Zed, so the skills carry over to whichever web development IDE your team uses.
Vim, Neovim and VS Code With Vim Keys
| Vim 9.2 | Neovim 0.12 | VS Code with VSCodeVim | |
|---|---|---|---|
| Config | ~/.vimrc, Vim script and Vim9 script | init.lua or init.vim | settings.json |
| Language servers | Plugins such as coc.nvim or ALE | Built in, with vim.lsp.enable | Built in |
| Syntax parsing | Regex-based syntax files | Tree-sitter | TextMate grammars and language servers |
| Plugin manager | Native packages, vim-plug | vim.pack, lazy.nvim | Marketplace |
| Installed on servers | Usually | Rarely | No, remote editing instead |
| Keys on this page | All | All | Most Normal and Visual mode keys; Ex commands partly |
Common Vim Mistakes
- Staying in Insert mode. Vim is fastest when Normal mode is home: insert, type, Esc, move.
- Pressing j and k twenty times. Use counts, search with / or relative line numbers and
12j. - Selecting with the mouse or Visual mode for everything. Text objects like
ci(are faster and repeatable with dot. - Losing a yank after deleting. Paste from register 0 with
"0p. - Copying a huge vimrc from the internet. Start small and add a line only when you understand why you need it.
- Using map instead of noremap. Recursive mappings break in confusing ways when plugins add their own.
How to Learn Vim Without Losing a Week
Days One and Two
Run vimtutor, or :Tutor in Vim 9.2 and Neovim, which takes about thirty minutes. Then edit real files with only i, Esc, :w, :q, hjkl, w, b, dd, yy, p, u and /. Do not install plugins yet.
Week Two
Add one new idea per day: text objects, then the dot command, then :%s and :g, then registers and macros, then splits and buffers. When you catch yourself repeating keys, look for the motion or object that does it in one step. The regex cheat sheet helps with search patterns, keeping in mind that Vim's default regex flavour needs backslashes that the \v very magic mode removes.
How This Vim Cheat Sheet Is Maintained
Every key and command in the tables was looked up by a script in the help of Vim 9.2, and options new in 9.2, such as autocomplete and tabpanel, were checked with exists() in the same Vim. The substitute, :global, :norm and macro examples were run in Vim 9.2 in Ex mode on the sample text shown, and the result was copied under each one. Neovim facts were checked against the Neovim 0.12 documentation and release notes.
Sources: Vim 9.2 :help, including index.txt, change.txt, motion.txt, pattern.txt and version9.txt; the Neovim 0.12 documentation and news; the vim-plug, vim-surround and vim-fugitive README files.
Vim Questions People Actually Ask
How do I exit Vim?
Press Esc to make sure you are in Normal mode, then type :q and Enter to quit, :wq to save and quit, or :q! to quit and throw away your changes. ZZ saves and quits without typing a colon. If keys are being inserted as text, Esc first is the step people miss.
How do I search and replace in Vim?
Use :%s/old/new/g to replace every match in the file, where % means every line and g every match on a line. Add c to confirm each replacement and i to ignore case, and wrap the word in \< and \> to match whole words only. Select lines first and press : to limit it to the selection.
How do I copy and paste in Vim?
yy copies a line and yiw a word, and p pastes after the cursor. To use the system clipboard, prefix with "+, as in "+yy and "+p, or add set clipboard=unnamedplus to your vimrc. Deleting also fills the default register, so "0p pastes the last thing you copied.
What are text objects in Vim?
Text objects are nouns you combine with operators: iw is the inner word, i" the text inside quotes, ip a paragraph and it the inside of an HTML tag. ciw changes a word, di( deletes a function's arguments and yap copies a paragraph, from anywhere inside the object.
How do I undo and redo in Vim?
Press u in Normal mode to undo and Ctrl+r to redo. The dot command repeats the last change. Vim keeps an undo tree, so g- and g+ move through every state, :earlier 10m goes back in time, and set undofile keeps the history after you close the file.
What is the difference between Vim and Neovim?
Neovim is a fork of Vim that uses Lua for configuration and plugins, ships a built-in language server client and Tree-sitter, and has a plugin manager in version 0.12. Vim keeps Vim9 script and stays closer to classic vi. The keys, modes and Ex commands on this page work in both.
How do I record and run a macro in Vim?
Press q and a letter, such as qa, to start recording into that register, do the edit, then press q to stop. @a runs it, @@ runs it again and 10@a runs it ten times. To run it on many lines, select them and type :norm @a.
How do I show line numbers in Vim?
Type :set number for absolute line numbers or :set relativenumber for numbers relative to the cursor, which make counts like 5j easy to read. Set both to see the current line's real number with relative numbers around it, and put the line in your vimrc to keep it.
Is Vim worth learning in 2026?
Yes, if you edit text for a living. Vim is installed on nearly every server, its keys work in VS Code, JetBrains IDEs, Zed and browsers through plugins, and the operator and motion model makes repetitive edits fast. Expect a slow first week and a payoff after a month.
Can I download this Vim cheat sheet as a PDF?
Yes. Use your browser's print command and choose Save as PDF. The print layout keeps every table, example and explanation and leaves out the search box, navigation and tools. Run a search first to print only the rows that are still visible.