How do I write and edit a macro as text instead of recording it live?
Write keystrokes in buffer, then "qy$
Instead of recording a macro in real-time (where mistakes mean starting over), you can write the keystrokes as text in a buffer, edit them visually, and then ya
category:
macros
tags:
#macros
#editing
#registers
#workflow
#best-practices
How do I create a self-repeating macro that runs until there is nothing left to process?
@q (inside macro recording)
A recursive macro calls itself as its last action, causing it to repeat indefinitely until it hits an error (like reaching end of file or failing a search).
category:
macros
tags:
#macros
#registers
#normal-mode
#editing
How do I re-insert the exact same text I typed during my last insert mode session?
Pressing while in insert mode inserts the same text that was typed during the previous insert mode session.
category:
editing
tags:
#insert-mode
#editing
#registers
How do I paste the contents of a register as a new line below the cursor regardless of the register type in Vim?
The :put Ex command always inserts a register's content as a new line below the current line, regardless of whether the register holds characterwise, linewise,
category:
editing
tags:
#registers
#editing
#paste
#ex-commands
#normal-mode
How do I paste the current filename into the buffer?
The % register in Vim always contains the name of the current file.
category:
registers
tags:
#registers
#editing
#insert-mode
#productivity
#filename
How do I make a macro prompt for user input at a specific point during its execution?
<C-r>=input('Enter: ')<CR>
By embedding =input('prompt: ') inside a recorded macro, you can pause the macro at any point to ask for user input and insert the result.
category:
macros
tags:
#macros
#insert-mode
#registers
#editing
How do I make a macro run repeatedly until it reaches the end of the file or encounters an error?
A recursive macro is a macro that calls itself at the end of its recording.
category:
macros
tags:
#macros
#editing
#normal-mode
#registers
How do I record a self-repeating recursive macro that automatically stops when it hits an error?
A recursive macro is one that calls itself at the end of its own recording.
category:
macros
tags:
#macros
#registers
#normal-mode
How do I write a Vim macro that automatically repeats until it fails?
A recursive macro is one that calls itself as its final action, causing it to repeat indefinitely until any command in the body fails (e.
category:
macros
tags:
#macros
#registers
#normal-mode
#editing
How do I create a macro that repeats itself until it hits an error or end of file?
A recursive macro is one that calls itself at the end of its own body.
category:
macros
tags:
#macros
#registers
#normal-mode
How do I create a self-repeating recursive macro that runs until it reaches the end of the file?
A recursive macro calls itself at the end of its recording, causing it to repeat automatically until an error — such as reaching the end of the file — stops
category:
macros
tags:
#macros
#registers
#editing
How do I filter the output of a Vim command to show only lines matching a pattern?
:filter /pattern/ {command}
:filter /pattern/ {command} runs any Ex command but suppresses every output line that does not match the pattern.
category:
command-line
tags:
#command-line
#ex-commands
#search
#buffers
How do I swap a word with the contents of a register using visual mode?
The viwp command visually selects the word under the cursor and replaces it with the contents of the unnamed register (your last yank or delete).
category:
visual-mode
tags:
#editing
#visual-mode
#registers
#paste
#productivity
How do I capture the output of a Vim command into a register or buffer?
:redir @a | {cmd} | redir END
The :redir command redirects the output of Ex commands to a register, file, or variable instead of displaying it on the screen.
category:
command-line
tags:
#command-line
#ex-commands
#registers
#productivity
#advanced
How do I save and restore macros across Vim sessions?
Vim can persist register contents (including macros) across sessions using viminfo (Vim) or shada (Neovim).
category:
macros
tags:
#macros
#persistence
#viminfo
#sessions
How do I collect all lines matching a pattern and copy them to the end of the file or a register?
The :g command combined with yank A (uppercase A to append) lets you collect every line matching a pattern into a single register without overwriting previous c
category:
command-line
tags:
#editing
#ex-commands
#global-command
#registers
#filtering
How do I copy a line to another location without yanking?
The :t (copy/transfer) command duplicates the current line and places it after the specified line number.
category:
editing
tags:
#editing
#ex-commands
How do I record a macro in Vim?
Recording a macro captures a sequence of keystrokes into a register, which you can replay later.
category:
macros
tags:
#macros
#normal-mode
How do I move a line or selection up or down in Vim?
The :move command relocates lines to a specific position without using delete and paste.
category:
editing
tags:
#editing
#move
#lines
#rearrange
How do I duplicate a visual selection of lines in Vim?
How it works The :copy command (or its abbreviation :t) duplicates lines to a specified destination.
category:
visual-mode
tags:
#visual-mode
#editing
#ex-commands