How do I run text I've yanked or typed as a Vim macro without recording it first?
@"
Vim macros are stored in registers — and you can execute any register as a macro with @{register}.
2125 results for "i' a'"
@"
Vim macros are stored in registers — and you can execute any register as a macro with @{register}.
:'<,'>g/let /normal! A;<CR>
When you need a structural edit in part of a file, Visual mode ranges combine well with :global and :normal!.
visual-mode #visual-mode #command-line #ex-commands #editing
:call setreg('a', "foo\nbar", 'b')
Most register examples focus on interactive yanks, but setreg() lets you construct registers programmatically, including their type.
/pattern/e
Search offsets let you place the cursor at a specific position relative to the match.
: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
qaA;<Esc>jq
This macro appends a semicolon to the current line and moves down, ready to repeat.
:set inccommand=split
Neovim's inccommand option provides real-time visual feedback as you type substitution commands.
:let @a = getreg('0')
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.
registers #registers #yanking #editing #command-line #refactoring
vim-startify plugin
vim-startify provides a configurable start screen when you open Vim without a file.
~ (in visual mode)
In visual mode, pressing ~ toggles the case of every character in the selection.
<C-v>jj$A
Combining visual block mode with $ and A lets you append text at the end of multiple lines, even when the lines have different lengths.
: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.
command-line #command-line #ex-commands #editing #normal-mode
:let @a .= getline('.') . "\n"
Named registers are usually filled with yanks and deletes, but they are also plain variables you can edit with Vimscript.
let @a = 'sequence'
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).
"ayv
Using named registers with visual mode lets you store multiple independent snippets simultaneously.
:nnoremap key command
The :nnoremap command creates a non-recursive normal mode mapping.
:[range]normal @a
The :[range]normal @a command runs a recorded macro against every line in a given range.
macros #macros #registers #ex-commands #normal-mode #advanced
:split #
In Vim, # is a special filename that always refers to the alternate file — the most recently active buffer before the current one.
:enew
The :enew command creates a new unnamed empty buffer in the current window.
:verbose set option?
The :verbose prefix shows where an option was last set (which file, which line).