【问题标题】:Color highlight function calls in VIMVIM 中的颜色高亮函数调用
【发布时间】:2020-09-22 21:03:27
【问题描述】:

有谁知道在 Vim 中为高亮函数调用着色的方法?

我知道有些插件可以通过记录标签来做类似的事情,但是根据我在网上找到的内容,我无法弄清楚如何让它工作。

我尝试过使用easy tags(顺便说一句,它似乎不再维护)和gutentags,但老实说,我还没有很接近制作它们中的任何一个上班。

另一方面,我想实现一个脚本来突出显示位于点和左括号或空格和左括号之间的任何内容会非常简单(如.anyCodeAtAll()anotherCode() ),但我不知道该怎么做。当然,这将是一个不完整的解决方案,但对于我目前的目的来说已经足够了。

有人知道怎么做吗?

【问题讨论】:

  • 你看过installation instructions for easy tags吗?您使用的是什么插件管理器(如果有)?
  • 我正在使用 Plug。据我所知,Easy tags 安装成功。
  • 看我的回答,想放这里但是格式有问题

标签: vim syntax-highlighting vim-plugin vim-syntax-highlighting


【解决方案1】:

可能是您没有正确安装插件。
尝试按照这些步骤(或追溯您的步骤),看看它是否有效/错过了任何步骤:

cd ~进入主目录。
vim .vimrc打开.vimrc
插入:

call plug#begin()  
Plug 'xolox/vim-easytags'  
call plug#end()

easytags#Options 表示 easytags 应该可以开箱即用,但您现在或以后可以在
.vimrc 文件中添加选项,
例如把:
let g:easytags_syntax_keyword = 'always'
在呼叫插头块之后。 无论如何。
:wq 写退出.vimrc

source ~/.vimrc 不确定是否需要,以后会这样做
vim test.js 用 test.whatever 你知道的语言打开 vim。
:PlugInstall 在 vi​​m
这里可能需要一些时间。
然后:q 走出那个窗口。
:source ~/.vimrc 这是需要的

然后测试一下你是否有语法高亮。 我很确定这是正确的。可能拼错了插件名称。

【讨论】:

    【解决方案2】:

    我的配置中有类似的东西,但它是特定于语言的。例如对于 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 行):

    除非有人有更好的解决方案,否则您可以根据您需要的语言调整上述内容。

    【讨论】:

    • 哇。那太棒了!感谢您的帮助:D
    • 如果答案对你有帮助,别忘了接受;-)
    猜你喜欢
    • 2018-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-04
    • 1970-01-01
    • 2011-03-29
    • 1970-01-01
    相关资源
    最近更新 更多