I use gvim to store recipes of commands that I will execute, depending on output. Currently, I select the text in gvim and paste the commands into a terminal console, but I bet there’s a way I can pass the visually selected range into a command-line for execution.
Share
Assuming you mean the Vim command line:
(if you mean the OS command line, see below).
For parts of lines (i.e. no end of line character), you could do something like this:
where
<C-R>means press Ctrl+R. They‘yanks’ the selected text, the:enters command mode,<C-R>"pulls the contents of the"(last yanked text) register onto the command line and<ENTER>(obviously) runs the command.If you want to do line-wise stuff, it’s a bit more complicated (as the command line doesn’t like
^Ms in the command). I’d recommend something like this in your vimrc:Select the lines (after restarting vim) and press
,r.Another way that you may find useful is to copy the lines you want, hit
q:to open the command line window and paste the lines you want into there and then move the cursor over the line you want and press ENTER. This has the advantage that you can edit the command before pressing ENTER. It’ll only run one command at a time.If you mean an (e.g.) Windows or Linux command line:
Use the function I listed above, but instead of:
use
or, if you want to see the result:
or
For more information: