Vim Tips Wiki
Register
Advertisement
Tip 409 Printable Monobook Previous Next

created January 21, 2003 · complexity basic · author Lyle · version 5.7


I wish to use selected text as part of a command - say, to substitute instances of a very long variable with a shorter name:

:%s/<selected text>/ShorterName/g

How do I do that?

Comments

  1. yank your selected text using the 'y' key.
  2. when entering your command you can use control-r followed by " whenever you need your selections. (control-r " inserts the contents of the "-register which is the standard register for yanking)

Just put the cursor over the word in your text. In the command line press <C-R><C-W> the to get the word.

See h: c_<C-R>_<C-W>


I have the following maps:

vmap ,g :s/<C-R>//
map ,g :s/<C-R>//

I then just add the closing delimiter and flags and hit return. These mappings have saved me a great deal of time.


Advertisement