I'm trying to edit the python.vim syntax file to duplicate the syntax highlighting for python in Textmate. The attached image illustrates the highlighting of function parameters which i'm struggling to achieve.
The self, a, b is highlighted in Textmate but not in Vim. I figured that I have to do the following.
Match a new region
syn region pythonFunction start="(" end=")" contains=pythonParameters skipwhite transparent
Try to match a string followed by a comma
syn match pythonParameters ".*" contained
So in point 2 the ".*" will match any string at the moment and must be expanded further to be correct. However i'm not sure if i'm on the right path since the match in 2 is not constrained to region between the brackets (). Any tips or input will be appreciated.
EDIT 1: If anyone wondered how it turned out eventually.
Here is my vim syntax highlighting for python.
EDIT 2: So just for ultimate thoroughness I created a github page for it.
http://pfdevilliers.github.com/Pretty-Vim-Python/
The command to enable syntax highlighting in vim is :syntax on , if you want it to be active everytime you launch vim, just add a line containing syntax on in your . vimrc file. maybe your vim doesn't have filetype detection enabled, try adding filetype on to your .
Syntax highlighting enables Vim to show parts of the text in another font or color. Those parts can be specific keywords or text matching a pattern. Vim doesn't parse the whole file (to keep it fast), so the highlighting has its limitations.
If you want to toggle this on/off (without creating a . vimrc file) simply type :syntax on while in vi/vim. Save this answer.
Ok, you've got a couple problems.
So, find the pythonFunction match, and change it to this:
syn match pythonFunction
\ "\%(\%(def\s\|class\s\|@\)\s*\)\@<=\h\%(\w\|\.\)*" contained nextgroup=pythonVars
Adding nextgroup tells vim to match pythonVars after a function definition.
Then add:
syn region pythonVars start="(" end=")" contained contains=pythonParameters transparent keepend
syn match pythonParameters "[^,]*" contained skipwhite
Finally, to actually highlight it, find the HiLink
section, and add:
HiLink pythonParameters Comment
Change Comment
to the grouping you want, or add your own. I'm using Statement
myself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With