Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: open a temporary buffer displaying executable's output

Tags:

vim

makefile

I have found the :cwindow command to be very useful and I was wondering if I could get similar functionality using the output of my compiled code. I'd the output of :!./a.out to appear in a "quickfix" style buffer.

I've also noticed that even after taking the standard steps to prevent the "Press Enter to continue" message, it still happens at least once on :make and :!./a.out - using :silent to suppress this causes my tmux to go completely blank. My current workaround involves a mapping with a lot of carriage returns, is there another way?

like image 431
J C Avatar asked May 08 '12 06:05

J C


1 Answers

Sure, you can use vim's preview window with a short function to execute the command, try this in your .vimrc:

fun! Runcmd(cmd)
    silent! exe "noautocmd botright pedit ".a:cmd
    noautocmd wincmd P
    set buftype=nofile
    exe "noautocmd r! ".a:cmd
    noautocmd wincmd p
endfun
com! -nargs=1 Runcmd :call Runcmd("<args>")

Then you can:

:Runcmd ls

And see the results of ls in your preview window

like image 99
Benj Avatar answered Sep 20 '22 03:09

Benj