Skip to content

Instantly share code, notes, and snippets.

Last active May 15, 2018 10:48
What would you like to do?
Capture output from a vim command (like :version or :messages) into a split scratch buffer.
":Page version
":Page messages
":Page ls
"It also works with the :!cmd command and Ex special characters like % (cmdline-special)
":Page !wc %
"Capture and return the long output of a verbose command.
function! s:Redir(cmd)
let output = ""
redir =>> output
silent exe a:cmd
redir END
return output
"A command to open a scratch buffer.
function! s:Scratch()
split Scratch
setlocal buftype=nofile
setlocal bufhidden=wipe
setlocal noswapfile
setlocal nobuflisted
return bufnr("%")
"Put the output of acommand into a scratch buffer.
function! s:Page(command)
let output = s:Redir(a:command)
call s:Scratch()
normal gg
call append(1, split(output, "\n"))
command! -nargs=+ -complete=command Page :call <SID>Page(<q-args>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment