How do I define or fix a macro using Vimscript instead of re-recording it?
:let @q = 'commands'
Macros in Vim are just text stored in named registers.
1034 results for "i" a""
:let @q = 'commands'
Macros in Vim are just text stored in named registers.
"qp
Macros are stored as plain text in named registers.
:tab drop filename
When working with many tabs, you often want to open a file — but only if it is not already open somewhere.
:s/pattern//gn
The :s///gn command counts how many times a pattern appears in the file without actually replacing anything.
command-line #search #ex-commands #substitution #command-line
:cdo s/old/new/ | update
:cdo {cmd} executes a command at every entry in the quickfix list, visiting each location in turn.
gq (visual mode)
Pressing gq on a visual selection reformats the selected lines to hard-wrap at textwidth columns.
highlight TrailingWhitespace ctermbg=red and match TrailingWhitespace /\s\+$/
How it works Vim's highlight and match commands let you create custom visual indicators.
<C-w>H
The H command moves the current window to the far left, making it a full-height vertical split.
/pattern\_s\+next
Vim's regular expressions support multi-line matching through underscore-prefixed atoms.
:%s/^/\=line('.').' '/
Vim's substitute command supports expressions in the replacement string using \=.
//
In Vim, pressing // (two forward slashes) in Normal mode repeats the last search pattern.
:g/pattern/normal @a
The :g (global) command combined with :normal @a lets you execute a recorded macro only on lines matching a pattern.
macros #macros #ex-commands #global-command #editing #automation
q: or <C-f> from : prompt
The command-line window (q:) opens a full Vim buffer containing your Ex command history.
r{char}
The r{char} command replaces the character under the cursor with {char} without ever entering insert mode.
:set operatorfunc=MyFunc<CR>g@{motion}
Vim's operatorfunc and g@ let you define custom operators that accept any motion or text object, just like built-in operators d, c, and y.
"/ register
The / register contains the most recent search pattern.
:execute "command"
The :execute command evaluates a string expression and runs it as an Ex command.
<C-r><C-r>{register}
In insert mode, {reg} pastes from a register but treats certain bytes as key inputs — so a register containing \n triggers a newline, \x08 triggers backspace,
"ayy "byy "cyy
How it works Vim provides 26 named registers (a through z) that you can use as independent clipboards.
/pattern/e
Search offsets let you place the cursor at a specific position relative to the match.