1

I would like to add in the following rule to my syntax to help with python files:

:syn match pythonBoolean "\<self\ze\."
:hi pythonBoolean cterm=bold

It works when I type it in directly to the file:

enter image description here

However, for the life of me, I cannot figure out how to have this as a default setting -- I've tried putting it in my vimrc, in an after folder, in a syntax file, etc. etc. but each time I get some error or other and it never ends up actually working properly.

What would be the simplest way to add the above two lines so that it will mark-up my python file with those changes (like it does when I enter it in directly)?

1
  • Did you try in a ~/.vim/after/syntax/python.vim file? That should work. You mentioned trying after and syntax but not sure if exactly this path... If this path doesn't work, what do you get instead when you query syntax and highlight?
    – filbranden
    May 24, 2020 at 4:24

1 Answer 1

1

Try using ~/.vim/after/syntax/python.vim:

syn match pythonSelf "\<self\.\@="
hi pythonSelf cterm=bold

I used a slightly different syntax group so you could customize it more; you could also hi link it to another group if you wanted.

1
  • 1
    I also avoid \zs and \ze in syntax matches because they make it difficult to apply syntax highlights to the characters « outside » of those matches.
    – D. Ben Knoble
    May 24, 2020 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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