Wednesday, 24 June 2009
Vim: Including a register's contents in a substitute
"sub "fred" with contents of register "a" (Control R)
:s/fred/<c-r>a/g
or from the paste buffer
s/fred/<c-r>*/g
Here you actually do a Control-R.
It is often preferable to do use the following
:s/fred/\=@a/g : better alternative as register not displayed
unfortunately the \=@a must be at the beginning of replacement string
zzapper
:s/fred/<c-r>a/g
or from the paste buffer
s/fred/<c-r>*/g
Here you actually do a Control-R.
It is often preferable to do use the following
:s/fred/\=@a/g : better alternative as register not displayed
unfortunately the \=@a must be at the beginning of replacement string
zzapper
Labels: substitute, vim
Comments:
<< Home
Thanks this is an excellent tip,
it worked well when I finally realised (as you said) I actually have to do a Ctrl-R on the keyboard. I wanted both strings to come from registers so it looked like this:
:%s/Ctrl-Ro/\=@l/g
(expanding the search string as it was typed.
it worked well when I finally realised (as you said) I actually have to do a Ctrl-R on the keyboard. I wanted both strings to come from registers so it looked like this:
:%s/Ctrl-Ro/\=@l/g
(expanding the search string as it was typed.
Subscribe to Post Comments [Atom]
<< Home
Subscribe to Posts [Atom]
Post a Comment