How do I append keystrokes to an existing macro without re-recording it?
:let @q .= "A;\<Esc>"
If a recorded macro is almost correct but missing a final step, re-recording from scratch is slow and error-prone.
870 results for "it at"
:let @q .= "A;\<Esc>"
If a recorded macro is almost correct but missing a final step, re-recording from scratch is slow and error-prone.
:set path^=./src
Vim's :set command supports three operators for modifying list-style options: += appends, -= removes, and ^= prepends.
gP
The gP command works like P (paste before the cursor) but leaves your cursor after the pasted text rather than at its beginning.
:%s/\r//g
When a file created on Windows is opened in Vim on a Unix system, lines may retain \r (carriage return) characters, displayed as ^M at the end of each line.
<C-a> (in insert mode)
While in insert mode, pressing re-inserts whatever text you typed during your previous insert session.
/foo\_.*bar
Vim's default .
:echo strtrans(@q)
When a macro behaves unexpectedly, :echo strtrans(@q) reveals exactly what is stored in register q—including invisible control characters—as human-readable
gM
The gM command moves the cursor to the horizontal middle of the current line, regardless of how long the line is.
:%s/\n/ /g
Using \n in the pattern of :substitute matches the newline character at the end of each line, letting you join lines with any separator you choose — something
\C
Vim's \C and \c atoms let you override ignorecase and smartcase on a per-pattern basis.
:set fileformat=unix
When you open a Windows file in Vim on a Unix system, you may see ^M at the end of every line — that's the carriage return (\r) from CRLF line endings.
: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
50%
Prefixing the % command with a count jumps the cursor to that percentage through the file.
:set spelloptions=camel
By default, Vim treats camelCase as a single word and flags it as a spelling error even when both camel and case are correctly spelled.
qa<C-r>=expression<CR>q
How it works The expression register (=) lets you evaluate Vimscript expressions and insert the result.
:let @a = @a . "\<CR>extra"
Vim stores macros as plain text in registers — the same registers used for yanked text.
:set makeprg=
The makeprg option defines the command that :make runs.
qa0f:dwj0q
How it works When recording a macro that you plan to repeat across multiple lines, the key technique is to end the macro positioned on the next line, ready for
/pattern1\&pattern2
Vim's \& operator lets you intersect two patterns so the match must satisfy both simultaneously.
:set winbar=%f
Neovim 0.