0

Is there a way to configure vim to make it more obvious when no error messages match any segment of errorformat? I'm trying to make it easier to debug my custom errorformat.


If you run a build for a project using :make, Vim will collect the output and apply the rules in the error format in order to populate the quickfix list.

As an example, here is a malformed C++ file that generates many errors when compiled using g++.

// foo.cpp
int main() {
c18fd8f7-f777-4f2a-9649-93d90977be2a;
c18fd8f7-f777-4f2a-9649-93d90977be2a;
c18fd8f7-f777-4f2a-9649-93d90977be2a;
c18fd8f7-f777-4f2a-9649-93d90977be2a;
c18fd8f7-f777-4f2a-9649-93d90977be2a;
c18fd8f7-f777-4f2a-9649-93d90977be2a;
c18fd8f7-f777-4f2a-9649-93d90977be2a;
c18fd8f7-f777-4f2a-9649-93d90977be2a;
}

For example,

~/git/example$ g++ foo.cpp |& tail
               ^~~~
foo.cpp:9:25: error: unable to find numeric literal operator ‘operator""d90977be2a’
 c18fd8f7-f777-4f2a-9649-93d90977be2a;
                         ^~~~~~~~~~~~
foo.cpp:10:15: error: unable to find numeric literal operator ‘operator""f2a’
 c18fd8f7-f777-4f2a-9649-93d90977be2a;
               ^~~~
foo.cpp:10:25: error: unable to find numeric literal operator ‘operator""d90977be2a’
 c18fd8f7-f777-4f2a-9649-93d90977be2a;
                         ^~~~~~~~~~~~

The default errorformat that Vim is built with on Unix-like platforms understands the GCC error format. Therefore, with no configuration, the quickfix list is populated correctly.

Running :make foo inside vim invokes the builtin make rule for creating an executable out of a C++ source file.

: (3 of 57): error: ‘c18fd8f7’ was not declared in this scope

The number 57 is a little misleading. That message means we are in line 3 out of 57 of the build output.

Running :cnext shows what is happening. We jumped over some intermediate output and landed on the next error.

(6 of 57): error: ‘f777’ was not declared in this scope   

Let's intentionally change the errorformat to something completely useless.

Suppose we now have a .vimrc consisting of just the line

let &errorformat = "00a8546c-9aa6-4402-81c2-ea8c606044cd"

With this, we can run :make foo as before.

However, we now stop on the first line of output

(1 of 57): g++     foo.cpp   -o foo

running cnext advances us to the next line

(2 of 57): foo.cpp: In function ‘int main()’: 

I think it's pretty clear what's happening. cnext probably scans the rest of the error message buffer for something matching an errorformat component. If cnext finds nothing, it falls back to advancing to the next line.

Is there a way of making more obvious when this has happened?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.