David542
David542

Reputation: 110163

Syntax highlighting within a string

To add a python syntax rule I will do something like this:

"Highlight the word self -- self.new, self
syn match pythonSelf    /\<self\>/
:hi pythonSelf          guifg=#5f9ba9

However, I would like to highlight any all-caps words and if they are ONLY in a python string. So for example, in the following image:

enter image description here

Line 15 should not have the ALTER word highlighted, but the words between lines 20-21 should be highlighted. Would it be possible to add something like:

syn match sqlKeyword      /[A-Z]\+/

But only if it's contained within a python string?

Upvotes: 1

Views: 220

Answers (1)

yolenoyer
yolenoyer

Reputation: 9445

You can try:

syn match sqlKeyword /[A-Z]\+/ containedin=pythonString contained

If you want to match all-caps words only, you might want to improve your pattern like this: /\<[A-Z]\+\>/.

Upvotes: 2

Related Questions