How do I copy lines to a different location in the file without overwriting my yank register?
:t
The :t command (short for :copy) copies addressed lines to a destination line number, leaving the unnamed register untouched.
:t
The :t command (short for :copy) copies addressed lines to a destination line number, leaving the unnamed register untouched.
[p
When you copy code from one indentation level and paste it at another, p preserves the original indentation, leaving your code misaligned.
:call setreg('"', @", 'l')
Vim registers carry not just their text content but also a type: charwise (c), linewise (l), or blockwise (b).
p (in visual mode)
In visual mode, pressing p replaces the selected text with the contents of the default register.
:let @q = 'commands'
Macros in Vim are just text stored in named registers.
"=
The expression register ("=) lets you evaluate any Vim expression and insert its result as text.
P (in visual mode)
When you paste over a visual selection using p (lowercase), Vim replaces the selection with your register contents — but the replaced text overwrites your unn
<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,
:let @q = "dwelp"
Recording macros with q works well for simple sequences, but complex macros with special keys can be hard to get right in one take.
qQ...q
When you record a macro into register q with qq.
:let @a = substitute(@a, 'old', 'new', 'g')
After recording a macro or yanking text into a named register, you may need to tweak it — fix a typo in a recorded macro, change a variable name in yanked tex
gp
The standard p command pastes text after the cursor but leaves the cursor at the beginning of the pasted text.
<C-a> (in insert mode)
While in insert mode, pressing re-inserts whatever text you typed during your previous insert session.
<C-r><C-o>{reg}
When you use a in insert mode to paste register a, Vim inserts the text as if you typed it character by character.
:put a ... edit ... "ayy
Recorded macros are stored as plain text in registers, but editing them by re-recording is tedious for complex sequences.
qqqqqq{edits}@qq
A recursive macro calls itself at the end of its sequence, creating a loop that automatically repeats until a motion or command fails (such as hitting the last
qaq qa...@aq @a
A recursive macro calls itself at the end of its recording, causing it to repeat indefinitely until a command inside it fails (like a search hitting the end of
qaqqa{actions}@aq@a
A recursive macro is a macro that calls itself at the end of its recording.
:<C-r>"
When typing an Ex command or search pattern, you often need to insert text you've already yanked or deleted.
:let @+ = @"
Vim's :let @{reg} syntax lets you read from one register and write to another.