Wikia

Vim Tips Wiki

Changes: Automatically open the quickfix window on :make

Edit

Back to page

(adjust previous/next navigation + minor manual clean)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 12: Line 12:
 
}}
 
}}
 
===Original idea===
 
===Original idea===
Put the following into your vimrc, then use <tt>:Make</tt> instead of <tt>:make</tt>.
+
Put the following into your vimrc, then use <code>:Make</code> instead of <code>:make</code>.
   
 
<pre>
 
<pre>
Line 21: Line 21:
 
</pre>
 
</pre>
   
Try this mapping so you can just press <tt>\j</tt> to make your program:
+
Try this mapping so you can just press <code>\j</code> to make your program:
 
<pre>
 
<pre>
 
:map <Leader>j :Make<CR>
 
:map <Leader>j :Make<CR>
 
</pre>
 
</pre>
   
You can use the new <tt>:Make</tt> command as an extension point for other customizations, too.
+
You can use the new <code>:Make</code> command as an extension point for other customizations, too.
   
 
==Automatically open the quickfix window on :make==
 
==Automatically open the quickfix window on :make==
Starting with Vim 7, there's no need for an additional <tt>:Make</tt> command; autocmds can be used to hook into the execution of the quickfix command, and open the quickfix window automatically:
+
Starting with Vim 7, there's no need for an additional <code>:Make</code> command; autocmds can be used to hook into the execution of the quickfix command, and open the quickfix window automatically:
   
 
<pre>
 
<pre>
Line 45: Line 45:
   
 
Note that the quickfix window will also automatically close in case the quickfix list becomes empty.
 
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 <tt>cwindow</tt> with <tt>copen</tt>.
+
If instead you always want to open the quickfix window, replace the <code>cwindow</code> with <code>copen</code>.
   
 
==Related==
 
==Related==

Latest revision as of 05:18, July 13, 2012

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