Vim errorformat string to show message in QuickFix removing part of it

308 Views Asked by At

I'm writing an errorformat string, and it works for the most part. My problem is that I have lines like this as the makeprg output:

Some text I want to show in the QuickFix window^M

Yes, the line ends with an spurious ^M character I want to remove. So, what I want in my QuickFix window is this, without the ^M character:

|| Some text I want to show in the QuickFix window

but I have this instead:

|| Some text I want to show in the QuickFix window^M

So far, this is the relevant part of my errorformat:

set errorformat=%+GSome text%m

I've tested, without success, something like this:

set errorformat=%+GSome text%m%-G^M%.%#

but it throws an error (not from the ^M which is a literal control-M char, not a caret followed by an M).

Obviously the solution is not using %G but I am at a loss here.

How can I remove the line ending character from the line here? And also, removing the initial || would be a plus, but I think it's impossible to do in Vim.

Thanks in advance!

Edited to make clearer how the input text looks

1

There are 1 best solutions below

0
On BEST ANSWER

Well, turns out I found a solution, probably not very good but it works, using trial and error.

set errorformat=%\\(Some Text%*[^.]).%\\)%\\@=%m

That is, the solution is using the Vim pattern (regex) expressions within errorformat, which has a quite arcane look but works, together with %* to match unknown text on the rest of the line

The solution uses \@=, a zero-width match, and requires some kind of terminator for the line, which appears before the ^M character I want to ignore, and some kind of text appearing somewhere on the line to match that line and not others.

Probably there is a much better solution but this is the best I could do myself.