performancematters
performancematters

Reputation: 75

Vim errorformat non-greedy match of %m operator

I have an errorfile which I want to be read by vi. The format looks as if:

myfile.txt_:_80_:_3_:_this is the message: oh no!_:_comment

I.e., filename, lineno, colno, message and comment separated by "_:_". Note the trailing "comment" which I do not want to appear in the vi message. However, when I use the errorformat string

:set errorformat=%f_:_%l_:_%c_:_%m

The "%m" operator has greedy matching and matches everything, including the whole "_:_comment" portion. This is even true if I make the errorformat

:set errorformat=%f_:_%l_:_%c_:_%m_:_

I do not know how to customize what text "%m" matches. The vi documentation speaks that pretty much everything that is possible with vi regex should be possible, but I cannot figure out a way to make it work (the documentation is vague in this respect in my opinion).

How can I use an errorformat that ignores the last column field?

Upvotes: 0

Views: 116

Answers (1)

romainl
romainl

Reputation: 196546

You can finish the format with the generic %s (for "search text"):

:set errorformat=%f_:_%l_:_%c_:_%m_:_%s

example

Note that this is relatively fragile. The following error, with several more _:_ separators:

myfile.txt_:_80_:_3_:_this is the message: oh no!_:_comment_:_foo_:_bar

would give you this message:

this is the message: oh no!_:_comment_:_foo

Improvement opportunities:

  • outside of Vim, make sure your errorfile is formatted in a non-ambiguous way,
  • in Vim, use a function to transform ambiguous error strings into non-ambiguous ones, see :help :cgetexpr.

Upvotes: 1

Related Questions