On 16 March 2011 08:47, sinbad <[email protected]> wrote:
> how to capture vim command output into a register or into a new
> window.

Ooh, I've just written my first attempt at a vimscript function
(feedback welcome).
It redirs to a variable, so doesn't use a register or a temp
file.
This should capture shell command output as well, eg ':RedirScratch !ls *.txt'

""""
"redirect output of command to a scratch buffer
"adapted from
"http://www.derekwyatt.org/2010/09/30/silently-redirecting-to-the-vim-clipboard/
function! RedirToScratchFunction(cmd, ...)
    let cmd = a:cmd . " " . join(a:000, " ")
    if cmd[0] == '!'
            "caputure shell output
            let cmd = cmd[1:]
            let captured = system( cmd )
    else
            "caputure vim output
            redir => captured
            exe cmd
            redir END
    endif
    "create disposable scratch buffer
    botright new
    setlocal nowrap
    setlocal buftype=nofile
    setlocal bufhidden=delete
    setlocal noswapfile
    put =captured
endfunction

command! -complete=command -nargs=+ RedirScratch
    \ silent! call RedirToScratchFunction(<f-args>)

""""

H.

-- 
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

Reply via email to