I would like to know if there is some way to color different comments in python inside VIM.

Today I use wombat256mod and I would like to color in red comments that start with double ## and color with gray the ones that start with a single #

Basically, it would differentiate to me that a ## means an English comment to help understand the code, while the # would just disable a statement in python.

1 Answer 1


You could do this with the syntax and highlight commands.

Step 1

First, we need to give a regex to match the correct lines, and name each "group"

syn match comment /^##.*/ 
syn match disabled /^##\@!.*/

The first regex is pretty simple. "Any line starting with two '#' characters". The second regex is slightly more complicated. "Any line starting with a '#', and not followed by another '#'".

Step 2

Now we just tell vim what to color text that matches these groups.

hi disabled guifg=gray ctermfg=gray
hi comment guifg=red ctermfg=red

"guifg" means "the color of the text (foreground) in the gui", and "ctermfg" means "the color of the text (foreground) in the terminal".

Of course, you could choose a different name then "disabled" and "comment". That's up to you.

Your Answer

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

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