2

An expansion of this question: How can I highlight all function names in Python files?

i have a sample:

src_file = replacement_file.replace(header_dir, source_dir)

here i need to match variable/arguments inside method/function, i need to match "header_dir", "source_dir"

Any suggestion is highly appreciated.

I'm working on the problem so will feedback to you via edit. thanks.

Edit 1: i try to match the function name, with help of @carpetsmoker i can match function name but can't match inside (), here:

syn match pFun "\v[[:alpha:]_.]+\ze(\s?\()" contained nextgroup=pFunVars
syn region pFunVars start="(" end=")" contained contains=pFunPara transparent keepend
syn match  pFunPara "[^,]*" contained contains=pythonString,pythonBrackets skipwhite

it doesn't match both function name and variables. highlight completely failed.

the fact is if i keep only:

syn match pFun "\v[[:alpha:]_.]+\ze(\s?\()"

function name match works. any clues?

EDIT 2: i guess match with end is ( and a region that start with "(" make it confused by regex engine. question is how can i separate the match pattern from ending with (, pattern contains ( and start of region is (, is that double "(" ?

EDIT 3: thanks @muru for suggestion, but it works partially,

syn region pFun matchgroup=Function \start="\v[[:alpha:]_.]+\ze(\s?\()" end=")" contains=pFun nextgroup=pFunPara
syn match pFunPara /\i*\ze\s*=[^,]/ contained contains=pythonString,pythonBrackets skipwhite

here, "pFunPara /\i*\ze\s*=[^,]/" i can't highlight the contains: pythonString, pythonBrackets inside pFunPara, @muru, do you have pattern to improve this? maybe loop via pFun make it impossible to highlight?

2
  • Something like vi.stackexchange.com/q/6731/205? Commented Oct 4, 2017 at 3:12
  • @muru: thanks for your help, pls refer to my edit 3. Commented Oct 4, 2017 at 4:03

1 Answer 1

2

Adapting the syntax commands I used in this answer and the default pythonFunction syntax match from Vim:

syn region pFun matchgroup=Function start='\h\i*\(\.\h\i*\)*\s*(' end=')' contains=pFun,pythonString,pythonNumber,pfunPara
syn match pFunPara /\v(\=\s*)?\zs\h\i*\ze\s*[,)]/ contained
hi pFunPara ctermfg=yellow
hi Function ctermfg=green

Gives me:

enter image description here

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.