Reputation: 284
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/
Upvotes: 10
Views: 2187
Reputation: 154103
Vim, Highlight matching Parenthesis ( ), square brackets [ ], and curly braces: { }
The config options for setting the colors of the foreground and background under the cursor when over a parentheses, square bracket or curly brace is this one:
hi MatchParen ctermfg=16 ctermbg=208 cterm=bold
To enable/disable the background color of the line under the cursor:
:set cursorline
:set nocursorline
To set the color of the background color of the line under the cursor:
hi VisualNOS ctermbg=999
hi Visual ctermbg=999
Here is my adaptation:
https://github.com/sentientmachine/erics_vim_syntax_and_color_highlighting
Upvotes: 0
Reputation: 14910
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.
Upvotes: 6