Created
April 16, 2010 11:01
-
-
Save tyru/368306 to your computer and use it in GitHub Desktop.
:Capture - Capture output of ex command.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Capture {{{ | |
function! s:get_output(...) "{{{ | |
" a:000 = [['echo', '"foo"'], 'messages', ...] | |
" | |
" TODO nested :redir ? | |
redir => output | |
for cmd_args in a:000 | |
if type(cmd_args) == type([]) | |
silent execute join(cmd_args) | |
else | |
silent execute cmd_args | |
endif | |
endfor | |
redir END | |
return substitute(output, '^\n\n', '', '') | |
endfunction "}}} | |
AlterCommand cap[ture] Capture | |
command! | |
\ -nargs=+ -complete=command | |
\ Capture | |
\ call s:cmd_capture(<q-args>) | |
function! s:cmd_capture(q_args) "{{{ | |
let out = s:get_output(a:q_args) " NOTE: Execute ex command in current buffer. | |
New " Change as you like. for e.g., :new instead. | |
silent file `=printf('[Capture: %s]', a:q_args)` | |
setlocal buftype=nofile bufhidden=unload noswapfile nobuflisted | |
call setline(1, split(out, '\n')) | |
endfunction "}}} | |
" }}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment