I'd like to select some text in vim and then execute it in bash. I know of the following procedure:
- select text using
V
orv
:!!
However, this replaces the selection with the output of the command. What if I don't want that?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityI'd like to select some text in vim and then execute it in bash. I know of the following procedure:
V
or v
:!!
However, this replaces the selection with the output of the command. What if I don't want that?
Type the :w
command like this:
:w !command
As you type it, it will appear like this:
:'<,'>w !command
See
:help :w_c
:w! command
by mistake. If command is a program you have write access to, it'll overwrite the program, and you won't be able to undo the change since that wasn't the buffer that was open.
In vim 8.0, you can select a range of lines and run :terminal bash
. This will open a terminal running bash
with your selection as stdin.
:terminal node
, :terminal ruby
, :terminal python
seem to work nicely as well.
E319: Sorry, the command is not available in this version
. Maybe one needs to build with special flags.