|
|
| 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: "zyw - 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 |
| |
|
|
|
| Line 21: |
Line 19: |
| |
|
|
|
| |
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> "zyw:exe "vs ".@z.""<CR> |
|
:map <F2> "zyw:exe "vs ".@z.""<CR> |
| |
</pre> |
|
</pre> |
| |
|
|
|
| − |
Pressing <F2> will open the file in vertically split window |
+ |
Pressing <F2> will open the file in vertically split window. |
| |
|
|
|
| |
b) Browsing a text file and saving all those difficult words you want to refer to during leisure |
|
b) Browsing a text file and saving all those difficult words you want to refer to during leisure |
| |
|
|
|
| |
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> "zyw<C-w>wo<Esc>"zp<C-w>w |
|
:map <F2> "zyw<C-w>wo<Esc>"zp<C-w>w |
| Line 39: |
Line 35: |
| |
|
|
|
| |
c) Help in help in help {{help|:help}} |
|
c) Help in help in help {{help|:help}} |
| − |
|
|
| |
<pre> |
|
<pre> |
| |
:map <F3> "zyw:exe "h ".@z.""<CR> |
|
:map <F3> "zyw:exe "h ".@z.""<CR> |
| Line 51: |
Line 46: |
| |
:vs <C-R><C-W><CR> |
|
:vs <C-R><C-W><CR> |
| |
</pre> |
|
</pre> |
| − |
Alternatively: |
+ |
Alternatively: |
| |
<pre> |
|
<pre> |
| |
:vs <cfile> <CR> |
|
:vs <cfile> <CR> |
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: "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
Some more examples:
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.
:map <F2> "zyw:exe "vs ".@z.""<CR>
Pressing <F2> will open the file in vertically split window.
b) Browsing a text file and saving all those difficult words you want to refer to during leisure
Open the text file and in a split window open an empty file.
:map <F2> "zyw<C-w>wo<Esc>"zp<C-w>w
yank the word under cursor, change window, paste and return
c) Help in help in help :help :help
:map <F3> "zyw:exe "h ".@z.""<CR>
Press <F3> on any word and we can see vim help for that keyword.
You can use <C-R><C-W> on the ':' command line to paste the word under cursor. So, to open a file in a vertically split window:
:vs <C-R><C-W><CR>
Alternatively:
:vs <cfile> <CR>
Anyway, there are alternatives to some of the examples given:
- "*": searches the word under cursor
- "gf": opens the file under the cursor
- "<C-W>f": same, horizontal split
Just want to note that your example:
:map <F2> "zyw<C-w>wo<Esc>"zp<C-w>w
works not only with the word under the cursor but with all selected text. Very useful for note-taking and so forth.