Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I need an extra escape in this vim errorformat?

Tags:

vim

I'm writing a compiler script for python. I have this errorformat that correctly parses Tracebacks:

CompilerSet errorformat=
          \%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,
          \%Z\ \ \ \ %m

I don't understand why I need the extra escape before the comma: why can't \"%f\"\\, be \"%f\"\,? I understand that the comma needs to be escaped because it's used to delimit sections of the errorformat, but why two backslashes?

Here's an example of a Traceback where the single escape doesn't work, but the double does:

Traceback (most recent call last):
File "test.py", line 9, in <module>
    g()
File "test.py", line 7, in g
    f()
File "test.py", line 4, in f
    raise IndexError()
IndexError

Another similar example is this python compiler script that uses three backslashes!

(I ask in the hopes that understanding why will make it easier to write more efm settings.)

like image 478
idbrii Avatar asked Feb 14 '26 01:02

idbrii


1 Answers

From :help efm-entries:

To include a comma in a pattern precede it with a backslash (you have to type two in a ":set" command). To include a backslash itself give two backslashes (you have to type four in a ":set" command). You also need to put a backslash before a space for ":set".

Inside 'errorformat', a comma is special, namely an entry separator. To match a literal comma, you have to escape it (once): \,. Okay, but in :set there's another round of escaping (e.g. to deal with spaces in the value), so the \ gets escaped another time: \\,. Often, you can avoid that second round of escaping by using :let (but not in the :CompilerSet command here).

like image 190
Ingo Karkat Avatar answered Feb 16 '26 15:02

Ingo Karkat