Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep a command output window in vim

Tags:

vim

What I'm looking for is a different window than the current one containing the output of a command into the same buffer. So I can execute:

:!php %

And see the output in a bottom split window. That's commonly seen in most graphical editors I've used.

Notes:

  1. Not the current window. Don't want to have to switch back
  2. Not creating a new buffer each time. (have to reuse "output" buffer)
  3. I don't want that in a register, I want to be able to see the output straight away.

The flow would be:

  1. Open vim -S session ...
  2. Edit a file
  3. Execute a simple make-type command
  4. Look at command output in output window

without having hundreds of new buffers and having to switch between windows.

What I've tried so far that is not satisfactory ... sending output to file, turning autoread on, opening a buffer on that file. That works but I have to turn autoread on for all files.. a bit annoying. Is there a way to turn autoread for a single buffer/file?

Thanks for your help.

like image 494
U0001 Avatar asked Sep 02 '11 02:09

U0001


1 Answers

It sounds like you are looking for Vim's "quickfix" window. I'd use 'makeprg', :make and :copen, like this:

:set makeprg=php\ %
:make
:copen

Additionally, you can use the 'errorformat' option to deliver the cursor to the first line containing an error.

:set errorformat=%m\ in\ %f\ on\ line\ %l

And for speed, I have F5 mapped to make:

:nnoremap <F5> :<C-U>make<CR>
like image 184
Johnsyweb Avatar answered Oct 24 '22 05:10

Johnsyweb