How do I execute a recorded macro a specific number of times?
5@q
Prefix the @ macro-execution command with a count to run the macro that many times in a row.
5@q
Prefix the @ macro-execution command with a count to run the macro that many times in a row.
:packadd matchit
The matchit plugin ships with Vim and Neovim but is not enabled by default.
o and O
In visual-block mode (), pressing o moves the cursor to the diagonally opposite corner of the selection, and O moves it to the other end of the same row (flippi
:/pattern1/,/pattern2/
Ex command ranges in Vim are not limited to line numbers and marks — you can use /pattern/ as a range boundary to select lines between any two matching patter
g~~
Vim has three case-change operators that work like any other operator — you can combine them with motions, text objects, or double them to act on the whole li
visual-mode #editing #visual-mode #normal-mode #text-objects
:argdo %s/old/new/g | w
:argdo {cmd} executes an Ex command against every file in the argument list—the set of files you opened Vim with or set explicitly with :args.
<C-v>jjI
Visual block mode () lets you select a rectangular region across lines.
"1p
Vim automatically stores your deletion history in numbered registers "1 through "9.
{N}@q
Prefix a macro invocation with a count to execute it up to N times in a single command.
:s/pattern/\=expr/g
Vim's :s command normally replaces matches with a literal string.
command-line #search #editing #ex-commands #command-line #registers
:let @q = substitute(@q, 'old', 'new', 'g')
When a recorded macro has a typo or needs a small tweak, re-recording the entire thing is error-prone.
<C-v> (in visual mode)
Once you are in any visual mode, pressing v, V, or switches to charwise, linewise, or blockwise visual mode respectively — without cancelling the current sele
n.
The n.
<C-e> / <C-y> (insert mode)
In insert mode, copies the character directly below the cursor (from the next line) and copies the character directly above (from the previous line).
:%!command
:%!{command} replaces the entire buffer contents with the output of piping them through a shell command.
qq{commands}@qq
A recursive macro calls itself at the end of its own definition, causing it to run repeatedly until Vim hits an error — such as reaching the end of the file o
:'<,'>!{cmd}
After making a visual selection and entering the command line with :, Vim automatically inserts the range ' for the selection.
gwip
The gw operator reformats text just like gq, but leaves the cursor in its original position after reformatting.
<C-v>I
Visual block mode's I command lets you type once and have the text inserted at the cursor column across all selected lines simultaneously.
"1p then u. to cycle through delete history
Vim silently maintains a rolling history of your last 9 deletions in numbered registers "1 through "9.