When entering an argument on the command, I know I can type <C-R><C-W>
to insert the word under the cursor and <C-R><C-A>
to insert the WORD under the cursor.
Is there a way to insert the current visual-selection?
Thanks!
When entering an argument on the command, I know I can type <C-R><C-W>
to insert the word under the cursor and <C-R><C-A>
to insert the WORD under the cursor.
Is there a way to insert the current visual-selection?
Thanks!
There are a few ways your question can be construed. The easiest is if you mean you want to give the selected text as a range argument to an ex command. I doubt this is your question, since this happens automatically if you type : with a visual selection, but the ex syntax for this
:'<,'>
The second way I think your question could be construed is that you want to insert the visual selected text itself as an argument to an ex command; I don't think this can be done. If you read the vim manual section 40.2, where range arguments are described, the only things that a command is allowed to grab from a range argument is the number of the first line and the last line (using the tags and ).
Finally, if you want to run the selected text on the shell command line, all you need to do is select it and type
:!sh
(The '<,'> part should get inserted for you between the : and the !. You can replace 'sh' with the command to start your favorite shell).
Hope this helps.
You can use the contents of any register on the ex or search command-lines with <C-R>
followed by the register's name. By yanking your visual selection, it is put into the 0
register, so <C-R>0
will add your yanked selection to the current command-line.
That is the only way I know of, but I still use it on a daily basis.