Execute a command and place the output in a buffer

2 Points

Andrew Radev Andrew Radev

10 years ago

Some vim commands output quite a lot of text and it would be nice to get the output in a more readable format. This command lets you do that. Simply prefix any command-line invocation with :Bufferize and you'll get the standard output in a Vim buffer.

Try these examples out:

:Bufferize digraphs

:Bufferize map

:Bufferize let g:

command! -nargs=* -complete=command Bufferize call s:Bufferize(<q-args>)
function! s:Bufferize(cmd)
  let cmd = a:cmd
  redir => output
  silent exe cmd
  redir END

  new
  setlocal nonumber
  call setline(1, split(output, "\n"))
  set nomodified
endfunction

Israel Chauca Fuentes

Israel Chauca Fuentes 10 years ago

Use <q-args> instead to skip join().

Israel Chauca Fuentes

Israel Chauca Fuentes 10 years ago

Also, you can use setline(1, split(output, "\n")) to avoid the extra line at the end of the buffer.

Andrew Radev

Andrew Radev 10 years ago

Good points, thanks :).