0

I am trying to add in a regex that matches either:

u'...'

or:

u"..."

To highlight the u before the string (it's a python thing).

This is what I have so far:

autocmd Syntax python syn match pythonUni       "\<\zsu\ze'" + '\|"'

Yet this gives me an invalid syntax when opening the python file. What would be the proper way to say ' or " in a vim regex?

I tested this out and the proper regex should be:

/\<\zsu\ze['"]

But I'm not sure how to put it in the quoted command above.

1 Answer 1

1

The argument to :syn match is not really a string, but a regex. Even though it's most often delimited by double quotes, you can use any other delimiters, such as slashes or pluses.

See :help :syn-pattern:

In the syntax commands, a pattern must be surrounded by two identical characters. This is like it works for the :s command. The most common to use is the double quote. But if the pattern contains a double quote, you can use another character that is not used in the pattern.

So in your case you can simply use:

syn match pythonUni /\<\zsu\ze['"]/

Or:

syn match pythonUni +\<\zsu\ze['"]+

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.