Vim Tips Wiki
We recommend that you log in before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your Watchlist. Creating an account is quick and free.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 13: Line 13:
 
}}
 
}}
 
During editing, there are many situations where one would like to do a command based on the word under cursor. Idea is to yank into a register and then use this register automatically. Basis of this functionality are two commands
 
During editing, there are many situations where one would like to do a command based on the word under cursor. Idea is to yank into a register and then use this register automatically. Basis of this functionality are two commands
*Yanking into a register, for example: "zyiw - will yank the word into z reg, "byy - yanks the line into b reg
+
*Yanking into a register, for example: "zyw - will yank the word into z reg, "byy - yanks the line into b reg
 
*Concatenating the register to a command and executing it. :exe "/".@z.""<CR> - searches for string in z reg
 
*Concatenating the register to a command and executing it. :exe "/".@z.""<CR> - searches for string in z reg
* Alternately you can replace @z by <C-r>z which will directly replace z by its content.
 
   
 
Some more examples:
 
Some more examples:
Line 21: Line 20:
 
a) Let's say that you have a file that has a list of files. You don't want to edit all the files, but selectively.
 
a) Let's say that you have a file that has a list of files. You don't want to edit all the files, but selectively.
 
<pre>
 
<pre>
:map <F2> "zyiw:exe "vs ".@z.""<CR>
+
:map <F2> "zyw:exe "vs ".@z.""<CR>
 
</pre>
 
</pre>
   
Line 30: Line 29:
 
Open the text file and in a split window open an empty file.
 
Open the text file and in a split window open an empty file.
 
<pre>
 
<pre>
:map <F2> "zyiw<C-w>wo<Esc>"zp<C-w>w
+
:map <F2> "zyw<C-w>wo<Esc>"zp<C-w>w
 
</pre>
 
</pre>
   
Line 37: Line 36:
 
c) Help in help in help {{help|:help}}
 
c) Help in help in help {{help|:help}}
 
<pre>
 
<pre>
:map <F3> "zyiw:exe "h ".@z.""<CR>
+
:map <F3> "zyw:exe "h ".@z.""<CR>
 
</pre>
 
</pre>
   
Line 59: Line 58:
 
Just want to note that your example:
 
Just want to note that your example:
 
<pre>
 
<pre>
:map <F2> "zyiw<C-w>wo<Esc>"zp<C-w>w
+
:map <F2> "zyw<C-w>wo<Esc>"zp<C-w>w
 
</pre>
 
</pre>
 
works not only with the word under the cursor but with all selected text. Very useful for note-taking and so forth.
 
works not only with the word under the cursor but with all selected text. Very useful for note-taking and so forth.
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel Editing help (opens in new window)