我的配置中有类似的东西,但它是特定于语言的。例如对于 Golang,我有一个 ~/.vim/after/go.vim,其中包含:
syntax match goCustomParen "(" contains=cParen
syntax match goCustomFuncDef "func\s\+\w\+\s*(" contains=goDeclaration,goCustomParen
" Exclude import as function name, for multi-line imports
syntax match goCustomFunc "import\s\+(\|\(\w\+\s*\)(" contains=goCustomParen,goImport
syntax match goCustomScope "\."
syntax match goCustomAttribute "\.\w\+" contains=goCustomScope
syntax match goCustomMethod "\.\w\+\s*(" contains=goCustomScope,goCustomParen
highlight def link goCustomMethod Function
highlight def link goCustomAttribute Identifier
highlight goCustomFuncDef ctermfg=13
highlight goCustomFunc ctermfg=43
highlight goCustomAttribute ctermfg=247
highlight goCustomMethod ctermfg=33
对于 Python,我有一个 ~/.vim/after/python.vim:
syntax match pyCustomParen "(" contains=cParen
syntax match pyCustomFunc "\w\+\s*(" contains=pyCustomParen
syntax match pyCustomScope "\."
syntax match pyCustomAttribute "\.\w\+" contains=pyCustomScope
syntax match pyCustomMethod "\.\w\+\s*(" contains=pyCustomScope,pyCustomParen
highlight def link pyCustomFunc Function
highlight def link pyCustomMethod Function
highlight def link pyCustomAttribute Identifier
highlight pyCustomFunc ctermfg=43
highlight pyCustomAttribute ctermfg=247
highlight pyCustomMethod ctermfg=33
在每种情况下,第一个块定义什么是函数、方法、属性等,第二个块将这些自定义定义链接到泛型类“函数、标识符...”,第三个块定义颜色。
文件需要在after目录中,在colorscheme和highlight定义之后执行。
以下是使用和不使用这些设置的并排比较(查看最后 3 行):
除非有人有更好的解决方案,否则您可以根据您需要的语言调整上述内容。