gpt4 book ai didi

vim - Vim 中的自定义语法高亮

转载 作者:行者123 更新时间:2023-12-04 14:35:13 28 4
gpt4 key购买 nike

如何突出显示以 sql_ 开头的字符串并在引号内?

我的日志文件:

MGPostgreSQLConnection.OpenQuery; "sql_p_factory_history"-ExecTime: 47ms
2010-11-12T17:28:18+01:00;custom; MGPostgreSQLConnection.OpenQuery; "sql_p_factory_history"-ExecTime+FetchTime: 47ms
2010-11-12T17:28:18+01:00;custom; MGPostgreSQLConnection.OpenQuery; "sql_factory"-ExecTime: 47ms
2010-11-12T17:28:18+01:00;custom; MGPostgreSQLConnection.OpenQuery; "sql_factory_contactperson"-ExecTime+FetchTime: 62ms

我的 vimrc(当然这行不通):
au BufRead,BufNewFile *.log syn match "sql_*"
au BufRead,BufNewFile *.log hi sql guifg=white guibg=red

最佳答案

你快到了!这个版本(有效和)不突出引号。

au BufRead,BufNewFile *.log hi sql guifg=white guibg=red ctermfg=white ctermbg=red
au BufRead,BufNewFile *.log syn match sql /"\zssql_\w*\ze"/

screen-shot

有关更多信息,请参阅以下内容:
  • :help :syn-match "用于语法匹配,erm,语法
  • :help /\zs "在那里设置比赛的开始
  • :help /\ze "在那里设置比赛结束
  • :help /\w "字字


  • 调试:

    命令 :verbose :syn应该给你这样的东西:
    --- Syntax items ---
    [...]
    sql xxx match /"\zssql_\w*\ze"/

    :verbose :hi :
            Last set from ~/.vimrc
    [...]
    sql xxx cterm=bold ctermfg=7 ctermbg=1 guifg=white guibg=red
    xxx应该与您指定的颜色相同(并且看起来像我的屏幕截图中的突出显示)。如果您没有看到这些,请检查您的 .vimrc (或 _vimrc 在 Windows 上)来源:
    :scriptnames
    1: /home/javh/.vimrc
    [...]

    当然,这只适用于:
    :echo has('syntax')

    ...返回 1 (或 :version 包括 +syntax )。

    关于vim - Vim 中的自定义语法高亮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4167425/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com