I'm writing a GitHub action that creates an annotation for files that would be reformatted when the black python formatter is run. For this, to work, I want to parse the following example output:

would reformat /home/ricks/Development/personal/errorformat/fmts/testdata/resources/python/num_guess.py
would reformat /home/ricks/Development/personal/errorformat/fmts/testdata/resources/python/subfolder/queen_problem.py
Oh no! 💥 💔 💥
2 files would be reformatted.

From this console output, I want to match the first two lines which show which files would be reformatted. I do this by using the %m %f error format matching syntax. In addition to this, I would like to ignore the last two lies. After reading this related post I came up with the following error format syntax:

%-G%Oh no!\ %m 
%-G%*\\d\ files%.%#
%m %f

This syntax, however, doesn't seem to work as it keeps matching the last two lines as a message with a file name %m %f. You can see this syntax in action in the following errorformat playground session.

If anybody knows the right syntax for only matching the first two lines I would be really grateful. Thanks a lot in advance!


There are a few minor issues with most of your lines ignoring specific patterns.

  1. %-G%Oh no!\ %m : You have an extra % there, turning the first character into a %O (a command to overread the matched part) rather than a literal O. You also have a trailing space there, so it would only match a line with a space at the end! You can fix that to %-GOh no!\ %m. Note that you don't actually need the \ to escape the space in this format, you only need it when using the :set command, since it breaks on whitespace. You can also just use %.%# at the end of the line, since you're ignoring this pattern anyways.

  2. %-G%*\\d\ files%.%#: Here you need a single backslash in %*\d to match a number. Note that this is using a scanf()-style pattern, you can also use a Vim regular expression here to match a sequence of digits, with %\d\+. You have one more issue on your playground for this one, you have no space before files, you have just \files over there, so that needs to be corrected too. Same as above, you don't need to backslash-escape the spaces here, only for a :set command.

  3. %-Q: This is a command to pop the last file from stack, but this only makes sense when using a corresponding %P to match a file name relevant for a block of messages. It doesn't look like that's the case here.

Here's the playground with minimal fixes to make it work, and here's a playground with more cleanup (removing the spurious %Q, the backslash escapes spaces, using regex for the digit match and a %.%# to match the end of the "Oh no!" line.)

  • 3
    I can't believe I've never seen that playground… incredibly useful!
    – D. Ben Knoble
    Dec 6 '20 at 17:35
  • 1
    Thank you so much for the detailed explanation. It really helped me clean up some gaps in my knowledge. You are a true vim (error format) master!
    – arcety
    Dec 7 '20 at 13:45
  • 1
    @D.BenKnoble The playground is indeed amazing. I was delighted when I found it. The only thing you have to keep in mind is that it does not yet support vim regex syntax (see github.com/reviewdog/errorformat).
    – arcety
    Jan 3 at 18:40

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.