Using selected text in a command
From Vim Tips Wiki
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:
How do I do that?
- yank your selected text using the 'y' key.
- 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.