How do I make Vim's diff mode produce cleaner, more readable diffs?
:set diffopt+=algorithm:patience,indent-heuristic
By default, Vim uses a basic longest-common-subsequence diff algorithm that can produce noisy, hard-to-read diffs.
:set diffopt+=algorithm:patience,indent-heuristic
By default, Vim uses a basic longest-common-subsequence diff algorithm that can produce noisy, hard-to-read diffs.
:args **/*.js
The :args command populates Vim's argument list with files matching a glob pattern, turning any set of files into a navigable list and enabling project-wide bat
<C-r>={expr}<CR>
The expression register ("=) lets you evaluate any Vimscript expression and insert the result directly into the buffer — all without leaving insert mode.
V]}
Pressing V]} in normal mode enters visual line mode and immediately extends the selection to the next unmatched closing brace }.
visual-mode #visual-mode #navigation #text-objects #editing #motions
:s/\v(\w+) (\w+)/\2 \1/
Vim's substitute command supports capture groups using \( and \) (or ( and ) in \v very-magic mode).
zg and zw
When Vim's spell checker marks a word as incorrect but it is intentionally spelled that way (a name, abbreviation, or domain-specific term), you can permanently
gI
Most Vim users know I to insert at the start of a line — but I actually jumps to the first non-blank character, skipping leading whitespace.
ysiw"
The ysiw" command wraps the word under the cursor in double quotes using the vim-surround plugin.
:argdo normal @a
The :argdo command applies any Ex command to every file in the argument list.
vip=
Pressing = in visual mode re-indents all selected lines according to the current filetype's indent rules — the same engine used by == for a single line, but a
visual-mode #visual-mode #indentation #editing #text-objects
:augroup
Wrapping autocmds in a named augroup with autocmd! at the start prevents duplicate autocommands from accumulating every time your vimrc is sourced.
:iabbrev
:iabbrev defines insert mode abbreviations — short strings that expand automatically when you type a non-keyword character (like space or Enter) after them.
"_d{motion}
Vim's black hole register (") acts as a write-only sink: anything sent to it is discarded without affecting any other register, including the unnamed register (
d/{pattern}<CR>
Vim lets you use a / search as a motion for any operator.
:put =system('cmd')
:put =system('cmd') lets you insert the output of any shell command as new lines in your buffer without leaving Vim.
:g/pattern/d A
Using :g/pattern/d A you can sweep through the entire buffer and extract every line that matches a pattern into register a, removing them from the buffer in the
:set nrformats-=octal
Vim's and increment and decrement numbers under the cursor.
=G
The =G command applies Vim's auto-indent operator (=) from the current line to the last line of the file (G).
\%#
The \%# atom in Vim's regex engine matches the exact position of the cursor — zero-width, between characters.
gR
gR enters Virtual Replace mode, a smarter variant of Replace mode (R) that replaces characters based on screen columns rather than raw bytes.