No luck with Google for this one, not even sure if it is a feature but
I've come across the need for it a few times:
I would like to be able to take a line (or buffer) in Vim and send it
to the shell in the fashion that :! can be used to execute shell
commands.
So for example if I have a readme.txt with the line:
sudo apt-get install lots of packages
I execute that line without resorting to yank / pasting.
Cheers,
Dave
See ":help filter".
(untested)
On Unix:
(single line)
:.!bash
:undo
(Visual: Vim inserts '<,'> when you hit the colon key)
:'<,'>!bash
:undo
(whole buffer)
:%!bash
:undo
On Windows, use cmd instead of bash
The line(s) will be replaced by the output of the external command, hence the
undo...
However, it's sometimes simpler to yank & paste, since then you don't have to
undo:
yank with
yy
paste on the Vim command-line:
:!<Ctrl-R>"<BS><Enter>
where <Ctrl-R> means "hit Ctrl-R" etc.
The <BS> (optional) is there to remove the Ctrl-M representing the end-of-line.
Or: yank in Vim, to the clipboard
"+yy
or (10 lines)
"+10yy
or (in linewise-visual)
"+y
then paste in a separate shell, using whatever (such as "Edit -> Paste")
applies to the terminal where the shell is running.
Best regards,
Tony.
--
Pittsburgh Driver's Test
(8) Pedestrians are
(a) irrelevant.
(b) communists.
(c) a nuisance.
(d) difficult to clean off the front grille.
The correct answer is (a). Pedestrians are not in cars, so they are
totally irrelevant to driving; you should ignore them completely.
On linux (I don't have other system to test) you can use
:.w !bash
:'<,'>w !bash
:w !bash
if it you don't need the undo.
--
«Dans la vie, rien n'est à craindre, tout est à comprendre»
Marie Sklodowska Curie
the help topic is:
:help :write_c
--
«Dans la vie, rien n'est à craindre, tout est à comprendre»
Marie Sklodowska Curie.
You could use RunView for this (see
http://mysite.verizon.net/astronaut/vim/index.html#RUNVIEW).
:[range]RunView[!] command (such as sh)
(visual-select)\rv (uses the string in g:runview_filtcmd (default:
"ksh") for the filter-command)
Regards,
Chip Campbell
:call system(getline('.'))
jkr
--
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us. (Calvin)