Wikia

Vim Tips Wiki

Automatically open the quickfix window on :make

Talk0
1,612pages on
this wiki
Revision as of 05:18, July 13, 2012 by JohnBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Tip 203 Printable Monobook Previous Next

created 2002 · complexity basic · author Padraic Renaghan · version 6.0


Original ideaEdit

Put the following into your vimrc, then use :Make instead of :make.

" Command Make will call make and then cwindow which
" opens a 3 line error window if any errors are found.
" If no errors, it closes any open cwindow.
:command -nargs=* Make make <args> | cwindow 3

Try this mapping so you can just press \j to make your program:

:map <Leader>j :Make<CR>

You can use the new :Make command as an extension point for other customizations, too.

Automatically open the quickfix window on :makeEdit

Starting with Vim 7, there's no need for an additional :Make command; autocmds can be used to hook into the execution of the quickfix command, and open the quickfix window automatically:

" Automatically open, but do not go to (if there are errors) the quickfix /
" location list window, or close it when is has become empty.
"
" Note: Must allow nesting of autocmds to enable any customizations for quickfix
" buffers.
" Note: Normally, :cwindow jumps to the quickfix window if the command opens it
" (but not if it's already open). However, as part of the autocmd, this doesn't
" seem to happen.
autocmd QuickFixCmdPost [^l]* nested cwindow
autocmd QuickFixCmdPost    l* nested lwindow

Note that the quickfix window will also automatically close in case the quickfix list becomes empty. If instead you always want to open the quickfix window, replace the cwindow with copen.

RelatedEdit

CommentsEdit

:cc      see the current error
:cn      next error
:cp      previous error
:clist   list all errors

Around Wikia's network

Random Wiki