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!
To get into the Vim Visual Line mode, press “Shift+V” while you are in Vim's Normal mode.
Place your cursor anywhere on the first or last line of the text you want to manipulate. Press Shift+V to enter line mode. The words VISUAL LINE will appear at the bottom of the screen. Use navigation commands, such as the Arrow keys, to highlight multiple lines of text.
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.
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 <line1>
and <line2>
).
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With