Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do not change current buffer when using vim quickfix window

Tags:

vim

I use VIM in the development of C++ projects and configured a compile shortcurt as follows

map <F4> :w<CR> :set makeprg=make<CR> :make <CR>:cw 4<CR>

which builds my project and shows the quickfix window in case there are any errors.

However this will always make vim open the file containing the first error in my current buffer, which is annoying when the error is not logically caused by the line indicated by the compiler but some other piece of code in the file that is currently openened. Can I prevent VIM from switching the currently openened file when jumping to an error (i.e. go to first error only if is contained in the current file, otherwise just open quickfix window). In addition: can I prevent jumping to the first error at all (again: just open quickfix window)

like image 924
dcn Avatar asked Sep 10 '11 14:09

dcn


2 Answers

To prevent the :make command from jumping to the first error, call it with ! modifier,

:make!

See :help :make, item 7.

like image 149
ib. Avatar answered Oct 16 '22 03:10

ib.


Besides using make! (with a bang), see also the 'switchbuf' option.

You could use set switchbuf=split to always use a new split when opening a file from quickfix.

Also check that you do not have set switchbuf=useopen, which might cause unexpected window/buffer changes while going through the quickfix list.

like image 26
blueyed Avatar answered Oct 16 '22 02:10

blueyed