How do I create text shortcuts that auto-expand while typing in Vim?
iabbrev
:iabbrev defines insert-mode abbreviations that expand automatically when you type a non-keyword character (space, punctuation, ) after the abbreviation.
Search Vim Tricks
Searching...iabbrev
:iabbrev defines insert-mode abbreviations that expand automatically when you type a non-keyword character (space, punctuation, ) after the abbreviation.
:.!{cmd}
:.
:vimgrep /pattern/ **
:vimgrep /pattern/ searches recursively through all files in the current working directory tree using Vim's own regex engine, populating the quickfix list with
'0
Pressing '0 in normal mode jumps to the exact cursor position in the most recently edited file, even after closing and reopening Vim.
:set opfunc and g@
Vim's operatorfunc option lets you define your own operators — just like the built-in d, y, or c — that accept any motion or text object.
\%l and \%c
Vim's \%l and \%c pattern atoms anchor a search to a particular line number or column, enabling surgical searches and substitutions that standard regex cannot e
%:h
Vim's filename modifiers let you derive path components from the current buffer's filename directly on the command line.
<C-y> and <C-e>
In Insert mode, copies the character at the same column position from the line above the cursor, and copies the character from the line below.
:[range]normal @q
The :[range]normal @q command replays the macro in register q on every line within a given range.
g]
g] is the disambiguation-aware alternative to .
:cdo s/old/new/ | update
:cdo {cmd} executes a command at every entry in the quickfix list, visiting each location in turn.
:packadd {name}
Vim 8+ and Neovim have a built-in package manager.
:'<,'>norm I//
After making a visual selection, :norm {commands} executes normal-mode keystrokes on every line in the range.
<C-g> and <C-t>
While the search prompt is open (with incsearch enabled), pressing advances the cursor to the next match and moves it to the previous match — all without leav
:noautocmd write
The :noautocmd modifier (abbreviated :noa) runs any subsequent Ex command while temporarily disabling all autocommand events.
:%s/pattern/\U&/g
Vim's substitute replacement string supports special case-transform atoms that change the case of matched text without requiring a second pass or an external to
mA to set, 'A to jump
Uppercase marks (A–Z) are global marks — they persist across files and Vim sessions.
\@= and \@! and \@<= and \@<!
Vim's regex engine supports zero-width lookahead and lookbehind assertions using the \@=, \@!, \@<=, and \@<! atoms.
{count}@{register}
Prefix any macro execution with a count to repeat it that many times in a single command.
g* and g#
The and # commands search for the exact whole word under the cursor (with word boundaries \).