Wikia

Vim Tips Wiki

Changes: Using selected text in a command

Edit

Back to page

(Move categories to tip template)
(Remove html character entities)
 
Line 14: Line 14:
 
I wish to use selected text as part of a command - say, to substitute instances of a very long variable with a shorter name:
 
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
+
:%s/<selected text>/ShorterName/g
   
 
How do I do that?
 
How do I do that?
Line 23: Line 23:
   
 
----
 
----
Just put the cursor over the word in your text. In the command line press &lt;C-R&gt;&lt;C-W&gt; the to get the word.
+
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_&lt;C-R&gt;_&lt;C-W&gt;
+
See h: c_<C-R>_<C-W>
   
 
----
 
----
 
I have the following maps:
 
I have the following maps:
   
vmap ,g :s/&lt;C-R&gt;//
+
vmap ,g :s/<C-R>//
map ,g :s/&lt;C-R&gt;//
+
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.
 
I then just add the closing delimiter and flags and hit return. These mappings have saved me a great deal of time.

Latest revision as of 08:40, September 29, 2008

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?

CommentsEdit

  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.


Around Wikia's network

Random Wiki