Thursday, June 28, 2012

Re: vim: use external program, but direct output to a new vsplitted buffer

There are many ways to do what you're asking for.

1) Don't bother because u = undo is that fast and copy the text manually
to a new buffer (c-w s then paste).

2) If you really need it that often that you want to write a script for
this is most simple:

map \doit :%! external-app > foo.txt<cr>u<c-w>s:r foo.txt<cr>
note that u undoes replacing the lines

now you may want to use a tempfile instead of foo.txt ...

Like this you can use <line1> and <line2> or such see :h command etc and
use system (which accepts input) which you can get by :h getline()
and join by :h join() (but \r\n may be replaced by \n then
thus byte count may differ)..

You can then paste the output of system to the new buffer by
puts=split(system("command", join(getline(lnum1,lnum2))))
or by using call append() or the like.

If you don't want to bother about all this lnum1 lnum2 stuff you can
also just yank to register by y and access that which would be shortest:

map \doit y<c-w>s:call append(split(system('command',@"),"\n"))<cr>

or such - but it pollutes your yank registers .. (you could use other
registers instead)

Marc Weber

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: