How do I use count prefixes to amplify motions and operators in Vim?
{count}{motion}
Almost every Vim motion and operator accepts a numeric count prefix that repeats or amplifies the action.
Search Vim Tricks
Searching...{count}{motion}
Almost every Vim motion and operator accepts a numeric count prefix that repeats or amplifies the action.
^ vs 0
Vim has two distinct motions for moving to the start of a line: 0 goes to column 1 (the absolute start), while ^ goes to the first non-blank character.
navigation #navigation #motions #line-navigation #indentation
`a vs 'a
Vim has two ways to jump to marks: backtick (` `) jumps to the exact line AND column, while apostrophe (') jumps to the line only, positioning the cursor at the
[m and ]m
The [m and ]m motions jump to the start of method/function definitions in languages with brace-delimited blocks.
qq;.q then @q or @@
The dot command (.
:wviminfo / :rviminfo
Vim can persist register contents (including macros) across sessions using viminfo (Vim) or shada (Neovim).
qa...@aq
A recursive macro calls itself at the end of its recording, causing it to repeat until a motion or search fails.
/pattern<CR>cgnreplacement<Esc>.
The gn text object selects the next search match, and cgn changes it.
f{char} ; ,
The f, F, t, and T motions search for a character on the current line.
:lvimgrep /pattern/ %
While :vimgrep populates the global quickfix list, :lvimgrep uses the window-local location list instead.
qa/pattern<CR>dd@aq
By starting a macro with a search command, the macro becomes conditional — it jumps to the next match before acting, and terminates when no more matches are f
:let g:debug_macro=1 | normal @a
When a macro doesn't work as expected, debugging it step by step is essential.
:move +1 / :move -2
The :move command relocates lines to a specific position without using delete and paste.
:%norm A;
The :%norm command runs normal mode commands on every line in the file (or a range).
:%!tac
Vim doesn't have a built-in reverse command, but you can pipe the buffer through tac (reverse of cat) to flip line order.
:set undofile undodir=~/.vim/undodir
By default, Vim's undo history is lost when you close a file.
:center 80
Vim has built-in text alignment commands that adjust lines relative to a specified width.
cia (with targets.vim) or daa
While Vim doesn't have a built-in argument text object, the targets.
<C-k>DG
Vim's digraph system lets you insert special characters by pressing followed by a two-character mnemonic code.
<C-r>=2+2<CR>
The expression register (=) in insert mode lets you evaluate any Vimscript expression and insert the result inline.