Skip to content

Instantly share code, notes, and snippets.

@ctechols
Last active May 15, 2018 10:48
Show Gist options
  • Save ctechols/c6f7c900b09be5a31dc8 to your computer and use it in GitHub Desktop.
Save ctechols/c6f7c900b09be5a31dc8 to your computer and use it in GitHub Desktop.
Capture output from a vim command (like :version or :messages) into a split scratch buffer.
"Examples:
":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
endfunction
"A command to open a scratch buffer.
function! s:Scratch()
split Scratch
setlocal buftype=nofile
setlocal bufhidden=wipe
setlocal noswapfile
setlocal nobuflisted
return bufnr("%")
endfunction
"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"))
endfunction
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