how to jump to the error position while compiling in vim?

0 views
Skip to first unread message

Jackie

unread,
Dec 17, 2008, 7:11:25 AM12/17/08
to v...@vim.org
Hi all:
 
I just compile my projects in vim like:
:!make
and after this step, there tips some warnings and errors, and then,
I press the "return" key, and vim jump to the first warning's place in the
projects. Absolutely, this is not my want. I hope it can jump to the
first error's place of the code, so how can I implement?
 
thanks!

fritzophrenic

unread,
Dec 17, 2008, 4:20:35 PM12/17/08
to vim_use
Use :make instead of :!make.

:help :make

If you do this, you can also see a list of all the errors and warnings
with :copen.

Tony Mechelynck

unread,
Dec 18, 2008, 1:34:56 AM12/18/08
to vim...@googlegroups.com, v...@vim.org

See
:help :compiler
:help :make

(the latter without a preceding exclamation mark) which will
automagically display the first error (if any) as soon as the make job
terminates. (Not sure if you'll get to the first _warning_ or _error_),
and a few other useful commands for use after that:

:cfir[st]
:cla[st]
:cn[ext]
:cp[revious]
:cnf[ile]
:cpf[ile]

for navigating the error list, and

:cope[n]
:ccl[ose]

to see it in its own window (the "quickfix" window), where hitting Enter
on an error moves to that line in the source. Of course, these commands
can be mapped for ease of use; for instance I have the following in my
vimrc:

:map <F2> :cnext<CR>
:map <S-F2> :cprev<CR>

which I use not so much for compiling but for the ":helpgrep" and
":vimgrep" commands (whose results also come in a quickfix window).

See also ":help quickfix.txt"


Best regards,
Tony.
--
Today is National Existential Ennui Awareness Day.

Jackie

unread,
Dec 18, 2008, 11:08:11 AM12/18/08
to vim...@googlegroups.com, fritzo...@gmail.com, antoine.m...@gmail.com, v...@vim.org
Hi! Thanks for your feedback!
I think perhaps, my previous description is not clearly enough, and make
you mistake my mind.

In a simple project, I did some tricks to make the compiler
report warning and error if we compiling.
And then, I open the .c file in vim, use the ':make'or ":!make" in vim
environment. Of course, we will get some "warning" and "error" in the
'quickfix' window. And then, we press the "Enter" key, the vim will
jump to the first place where "warning" or "error" happened.
Now, the problem is I do want vim jump to the first place where "error"
happened, not "warning".

For example:
there is a file "hello.c"
1: #include <stdio.h>
2:
3: void main ()
4: {
5: return 0;
6: }
7: klkjlj /* to create an error here*/

if we open it in vim, and execute ":make", the 'quickfix' window will get
/******************************************************
[Quickfix List]
|| cc -c hello.c -o hello.o
|| hello.c: In function 'main':
hello.c|5| warning: 'return' with a value, in function returning void
hello.c|3| warning: return type of 'main' is not 'int'
|| hello.c: At top level:
hello.c|7| warning: data definition has no type or storage class
hello.c|7| error: expected '=', ',', ';', 'asm' or '__attribute__' before
'klkjlj'
|| make: *** [hello.o] Error 1

*******************************************************/
and if we press "Enter" key , the vim cursor will stop at line 5 in
"hello.c" where
the warning happened. But I do want the vim cursor can stop at line 7 where
the
error happened.
How can I implement?

--------------------------------------------------
From: "Tony Mechelynck" <antoine.m...@gmail.com>
Sent: Thursday, December 18, 2008 2:34 PM
To: <vim...@googlegroups.com>
Cc: <v...@vim.org>
Subject: Re: how to jump to the error position while compiling in vim?

fritzophrenic

unread,
Dec 18, 2008, 11:23:00 AM12/18/08
to vim_use
Oh, so you basically want to ignore warnings (ugh, but oh well, your
choice...).

You may be able to edit the 'errorformat' option to not pick up the
warnings at all...which would make only errors show up in the quickfix
window, etc.

What I sometimes do is just open the quickfix window and search for
"error" with a simple '/' search before hitting enter.
Reply all
Reply to author
Forward
0 new messages