How do you use a register value in a substitute command?
:%s/<C-r>a/replacement/g
In command-line mode, a inserts the contents of register a.
65 results for "S substitute line"
:%s/<C-r>a/replacement/g
In command-line mode, a inserts the contents of register a.
:%s/\<\w\+\>/\=toupper(submatch(0))/g
The \= flag in the replacement part of :substitute tells Vim to evaluate what follows as a Vimscript expression instead of treating it as a literal string.
:s/pattern/replace/flags
The substitute command supports several flags that modify its behavior.
:%s/^/\=line('.').' '/
Vim's substitute command supports expressions in the replacement string using \=.
: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
:&&
After running a :s/pattern/replacement/g command, you often need to repeat it on another line or range.
:%s/,/\r/g
In Vim's substitute command, \r in the replacement string inserts a newline.
:%s/pattern//gn
The n flag on the substitute command reports the number of matches without performing any substitution.
:%s/pattern/\=@0/g
The \=@0 replacement expression inserts the contents of register 0 (last yank) as the replacement text.
:'<,'>s/\%Vpattern/replacement/g
Using \%V in a substitute pattern restricts matching to within the visual block area only, rather than the full lines.
&
The & command in normal mode repeats the last :s substitution on the current line.
search #search #substitution #ex-commands #repeat #normal-mode
:%s/old/new/g
The :%s/old/new/g command replaces all occurrences of old with new across every line in the file.
:help topic
Vim has an extensive built-in help system.
\u and \l in :s replacement
Vim's substitute command supports special case modifiers in the replacement string that let you change the case of captured text on the fly.
q/k?pattern<CR>
Vim's command-line history window (q: for Ex commands, q/ for search) opens a full editing buffer containing your history.
g&
The g& command repeats the last substitute command across the entire file.
:s/\v(pattern1)(pattern2)/\2\1/
Vim's substitute command supports capture groups (also called backreferences), which let you rearrange matched portions of text.
:%s/pattern/\=expression/g
Vim's substitute command supports expression replacements using \= in the replacement string.
:keeppatterns %s/old/new/g
The :keeppatterns modifier runs any Ex command without modifying Vim's last search pattern (stored in @/).
command-line #search #ex-commands #command-line #substitute #registers
:s/,/\r/g
In Vim's substitute command, use \r (not \n) in the replacement to insert a real newline.