Vim / Neovim Cheat Sheet
A modal editor. Normal mode is for moving and commands, Insert mode is for typing, Visual mode is for selecting. When in doubt, press Esc. To learn, run vimtutor (Vim) or :Tutor (Neovim).
On this page
Survival #
| Key | Action |
|---|---|
i | Insert before the cursor |
Esc | Back to Normal mode |
:w | Save |
:q | Quit |
:wq or ZZ | Save and quit |
:q! | Quit without saving |
u / Ctrl + r | Undo / redo |
Entering Insert Mode #
| Key | Action |
|---|---|
i / a | Insert before / after the cursor |
I / A | Insert at the start / end of the line |
o / O | New line below / above |
s | Delete a character and insert |
cc or S | Replace the whole line |
Moving #
| Key | Action |
|---|---|
h j k l | Left, down, up, right |
w / b / e | Next word / previous word / end of word |
0 / ^ / $ | Line start / first character / line end |
gg / G | First / last line |
42G or :42 | Go to line 42 |
% | Jump to the matching bracket |
{ / } | Previous / next paragraph |
Ctrl + d / Ctrl + u | Half page down / up |
f x / t x | Jump to / before the next "x" on the line (; repeats) |
H / M / L | Top / middle / bottom of the screen |
Editing #
| Key | Action |
|---|---|
x | Delete a character |
dd | Delete (cut) the line |
yy | Copy (yank) the line |
p / P | Paste after / before |
dw / cw | Delete word / change word |
diw / ciw | Delete / change the whole word under the cursor |
ci" / ci( / cit | Change inside quotes / brackets / HTML tag |
D / C | Delete / change to the end of the line |
r x | Replace the character with x |
J | Join the next line onto this one |
>> / << | Indent / unindent |
. | Repeat the last change |
3dd, 5j… | Put a number before a command to repeat it |
Pattern: operator + motion, for example d (delete), c (change), y (yank) + w, $, iw, i", ap…
Visual Mode #
| Key | Action |
|---|---|
v | Select characters |
V | Select lines |
Ctrl + v | Block (column) select |
then d / y / c / > | Delete / copy / change / indent the selection |
Ctrl + v, select, I, type, Esc | Type on several lines at once |
Search & Replace #
| Command | Action |
|---|---|
/text / ?text | Search forward / backward |
n / N | Next / previous match |
* / # | Search the word under the cursor |
:%s/old/new/g | Replace everywhere in the file |
:%s/old/new/gc | Replace with confirmation |
:s/old/new/g | Replace on the current line only |
:noh | Clear the search highlight |
Files, Buffers & Splits #
| Command | Action |
|---|---|
:e file | Open a file |
:ls / :bn / :bp | List buffers / next / previous |
:sp / :vsp | Horizontal / vertical split |
Ctrl + w then h j k l | Move between splits |
Ctrl + w w | Cycle splits |
:tabnew / gt | New tab / next tab |
:!cmd | Run a shell command |
Macros & Marks #
| Key | Action |
|---|---|
qa … q | Record a macro into register a |
@a / @@ | Play macro a / repeat the last macro |
ma / 'a | Set mark a / jump to mark a |
Ctrl + o / Ctrl + i | Jump back / forward in history |
Settings #
| Command | Action |
|---|---|
:set number / :set relativenumber | Line numbers |
:set paste | Paste without auto-indent (classic Vim) |
:syntax on | Syntax highlighting |
~/.vimrc | Vim config |
~/.config/nvim/init.lua | Neovim config (Lua) |
:checkhealth | Neovim: diagnose setup problems |
-- minimal init.lua
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
vim.opt.clipboard = "unnamedplus" -- use the system clipboard
Nothing on this sheet matches “”.