How do I edit a macro in-place using Vimscript without re-recording it?
:let @a = substitute(@a, "old", "new", "g")
When a recorded macro has a typo or wrong command buried inside it, you don't have to re-record the entire thing.
90 results for "%s/old/new/g"
:let @a = substitute(@a, "old", "new", "g")
When a recorded macro has a typo or wrong command buried inside it, you don't have to re-record the entire thing.
:argdo %s/old/new/g | w
:argdo {cmd} executes an Ex command against every file in the argument list—the set of files you opened Vim with or set explicitly with :args.
:cfdo %s/old/new/g | update
The :cfdo %s/old/new/g update command performs a search and replace across every file in the quickfix list and saves each one.
:call setreg("a", substitute(getreg("a"), "old", "new", "g"))
The getreg() and setreg() functions let you read and write register contents as plain strings, making it possible to surgically edit a macro without re-recordin
:cdo s/old/new/ | update
:cdo {cmd} executes a command at every entry in the quickfix list, visiting each location in turn.
:args **/*.py | argdo %s/old/new/gc | update
Vim can perform search-and-replace across multiple files without any plugins by combining the arglist with :argdo.
search #search #substitution #ex-commands #productivity #quickfix #arglist
:argdo %s/\<old\>/new/ge | update
When you need to apply the same substitution across a curated set of files, :argdo is safer than a broad project-wide command.
command-line #command-line #ex-commands #search #buffers #formatting
:%s/old/new/gc
Adding the c flag to a substitute command makes Vim pause at every match and ask you whether to replace it.
:cfdo %s/old/new/ge | update
When you grep across your project and want to perform a search-and-replace on every file that matched, :cfdo is the most efficient approach.
command-line #quickfix #substitute #search #ex-commands #editing
:args **/*.js | argdo %s/old/new/ge | update
The argument list (arglist) is Vim's mechanism for loading a set of files and running commands across all of them.
command-line #command-line #ex-commands #arglist #productivity #batch #editing
:Subvert
The vim-abolish plugin's :Subvert command (abbreviated :S) substitutes a word across all its case variants simultaneously.
:s#pattern#replacement#g
Vim's substitution command accepts any non-alphanumeric, non-whitespace character as the delimiter — not just /.
:s/pattern/replace/flags
The substitute command supports several flags that modify its behavior.
:cdo {cmd}
:cdo executes an Ex command on every entry in the quickfix list in sequence, visiting each match in turn.
Use :s/pat/rep/e flag or :silent! prefix
By default, Vim macros abort on the first error — a failed search, a substitute with no matches, or a movement that can't be performed.
:{start},{end} command
Ex commands accept range specifiers that control which lines are affected.
g- / g+
Vim doesn't have a simple linear undo stack — it maintains a full undo tree with branches.
editing #editing #undo-redo #normal-mode #advanced #productivity
:/start/,/end/command
Vim allows pattern-based ranges in Ex commands, letting you operate on lines between two search matches.
gh
Vim's Select mode behaves like the familiar selection model in most GUI editors: after selecting text, any printable character you type replaces the selection a
:'<,'>s/pattern/replacement/g
When you make a visual selection and then type :, Vim automatically inserts ' as the range — the marks for the start and end of the last visual selection.