How do I collect all lines matching a pattern into a register without leaving them in place?
Using :g/pattern/d A you can sweep through the entire buffer and extract every line that matches a pattern into register a, removing them from the buffer in the
category:
registers
tags:
#registers
#ex-commands
#search
#editing
#global
How do I clear or reset a specific register in Vim?
Registers persist their contents throughout your Vim session and even across sessions if viminfo or shada is enabled.
category:
registers
tags:
#registers
#clear
#reset
#management
How do I replace a character or pattern with a newline in a substitute command?
In Vim's substitute command, \r in the replacement string inserts a newline.
category:
editing
tags:
#editing
#substitute
#newline
#text-manipulation
How do I use marks to define a range for Ex commands?
Marks can be used as range specifiers in any Ex command.
category:
command-line
tags:
#marks
#command-line
#ex-commands
#ranges
#editing
How do I copy the most recent yank into a named register without yanking again?
When you want to preserve a valuable yank before doing destructive edits, copying register 0 into a named register is safer than re-yanking text.
category:
registers
tags:
#registers
#yanking
#editing
#command-line
#refactoring
How do I append the current filename to a named register from Ex command-line?
:let @a .= expand('%:t') . "\n"
Named registers are not just for yanks and deletes.
category:
registers
tags:
#registers
#command-line
#automation
#editing
How do I add text to the end of every line in a range?
The :normal command executes normal-mode keystrokes on every line in a range.
category:
command-line
tags:
#command-line
#ex-commands
#editing
#normal-mode
#batch-editing
How do I edit a recorded macro by modifying it as text in a buffer?
Recorded macros are stored as plain text in registers, but editing them by re-recording is tedious for complex sequences.
category:
macros
tags:
#macros
#registers
#editing
How do I programmatically create a blockwise register with setreg()?
:call setreg('a', "foo\nbar", 'b')
Most register examples focus on interactive yanks, but setreg() lets you construct registers programmatically, including their type.
category:
registers
tags:
#registers
#vimscript
#automation
#editing
How do I restrict a substitution to the range between two named marks?
Named marks can serve as range endpoints for any Ex command, including :substitute.
category:
search
tags:
#search
#marks
#substitution
#ex-commands
#editing
How do I run a macro a specific number of times without using a recursive macro?
Prefix a macro invocation with a count to execute it up to N times in a single command.
category:
macros
tags:
#macros
#registers
#normal-mode
#editing
How do I put a register as true line list so embedded newlines stay split correctly?
Most register pastes are character-oriented, but advanced edits often need to preserve exact line structure.
category:
registers
tags:
#registers
#ex-commands
#scripting
#text-processing
How do I append a semicolon to every non-blank line with one Vim command?
:g/[^[:space:]]/normal! A;\<CR>
When you need to patch many lines at once, :g with :normal! is often faster and safer than recording a macro.
category:
command-line
tags:
#command-line
#ex-commands
#editing
#normal-mode
How do I record a macro to wrap each line in HTML tags?
qaI<li><Esc>A</li><Esc>jq
This macro wraps each line in tags by inserting the opening tag at the start and appending the closing tag at the end.
category:
macros
tags:
#macros
#editing
How do I save a macro permanently in my vimrc?
How it works Macros recorded with q are stored in registers, but they are lost when you close Vim (unless you have the viminfo or shada file preserving them).
category:
macros
tags:
#macros
#registers
#config
How do I check whether a register contains characterwise, linewise, or blockwise text?
The getregtype() function returns the motion type of a register's content — whether it was yanked characterwise, linewise, or as a visual block.
category:
registers
tags:
#registers
#ex-commands
#macros
How do I delete a word and save it to a specific register?
The "adiw command deletes the inner word under the cursor and stores it in register a.
category:
registers
tags:
#registers
#editing
#text-objects
How do I run a one-off macro without recording by executing keystrokes from an expression register?
Recorded macros are powerful, but sometimes you need a quick ephemeral sequence and do not want to occupy a register.
category:
macros
tags:
#macros
#registers
#normal-mode
#automation
How do I inspect a Vim register's full details including its type (charwise, linewise, or blockwise) in Vimscript?
getreginfo('{reg}') (Vim 8.
category:
registers
tags:
#registers
#normal-mode
How do I append the current line to a register from command line without using yank?
:let @a .= getline('.') . "\n"
Named registers are usually filled with yanks and deletes, but they are also plain variables you can edit with Vimscript.
category:
registers
tags:
#registers
#command-line
#vimscript
#editing