突出显示三个单引号中的字符串作为注释?

2024-06-06 19:06:05 发布

您现在位置:Python中文网/ 问答频道 /正文

this开始,我想突出显示三个引号中的字符串作为注释(或者更好的方法是针对那些不是类/函数/模块中的第一个东西的字符串)。在

我正在使用jedi-vim。以下是文件after/syntax/python.vim的内容:

syn match pythonComment "#.*$" contains=pythonTodo,@Spell,jediFunction
syn region pythonString
    \ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
    \ contains=pythonEscape,@Spell,jediFunction
syn region pythonString
    \ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend
    \ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell,jediFunction
syn region pythonRawString
    \ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
    \ contains=@Spell,jediFunction
syn region pythonRawString
    \ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend
    \ contains=pythonSpaceError,pythonDoctest,@Spell,jediFunction

我尝试删除pythonString行中的三个单引号,并添加以下内容之一:

^{pr2}$

正如this主题中建议的那样,但它不起作用(三个单引号和双引号中的字符串都突出显示为docstring)。在


更新2014年2月14日星期五08:29:00

@benjifisher

我确信它被认为是pythonString,因为{}告诉了我。在

:syn list pythonString

--- Syntax items ---
pythonString   xxx start=/[uU]\=\z(['"]\)/ skip=/\\\\\|\\\z1/ end=/\z1/  contains=pythonEscape,@Spell
                   start=/[uU]\=\z("""\)/ end=/\z1/  keepend contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell
                   start=/[uU]\=\z(['"]\)/ skip=/\\\\\|\\\z1/ end=/\z1/  contains=pythonEscape,@Spell,jediFunction
                   start=/[uU]\=\z("""\)/ end=/\z1/  keepend contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell,jediFunction
                   links to String

:syn list pythonComment

--- Syntax items ---
pythonComment  xxx match /#.*$/  contains=pythonTodo,@Spell
                   match /#.*$/  contains=pythonTodo,@Spell,jediFunction
                   start=/'''/ end=/'''/
                   start=/[uU]\=\z('''\)/ end=/\z1/  keepend contains=pythonTodo,@Spell,jediFunction
                   start=/^\s*[uU]\?[rR]\?'''/ end=/'''/  keepend excludenl contains=pythonEscape,@Spell,pythonDoctest,pythonDocTest2,pythonSpaceError
                   links to Comment

Tags: startregionenduucontainssynspellz1
1条回答
网友
1楼 · 发布于 2024-06-06 19:06:05

哦,对不起,是我的错。在

由于我在第一行(pythonComment)之后添加了建议的行,我还必须删除第二行的单引号:

syn match pythonComment "#.*$" contains=pythonTodo,@Spell,jediFunction
syn region pythonComment start=/'''/ end=/'''/
syn region pythonString
    \ start=+[uU]\=\z(["]\)+ end="\z1" skip="\\\\\|\\\z1"
    \ contains=pythonEscape,@Spell,jediFunction

教训是:我应该在下一次文件末尾添加:D

相关问题 更多 >