突出显示 python 文档字符串作为注释(vim 语法突出显示) [英] Highlight python docstrings as comments (vim syntax highlighting)

查看:64
本文介绍了突出显示 python 文档字符串作为注释(vim 语法突出显示)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以修改python.vim(以及相应的colorcheme 文件),这样在 vim 下的 python 语法高亮显示期间,class 和 def 语句(又名文档字符串)下的三重引号字符串将被高亮显示为注释?

Is it possible to modify python.vim (and the corresponding colorscheme file) such that triple-quoted strings right under class and def statements (a.k.a. docstrings) will be highlighted as comments during python syntax highlighting under vim?

class URLopener:
  """Class to open URLs.
  This is a class rather than just a subroutine because we may need
  more than one set of global protocol-specific options.
  Note -- this is a base class for those who don't want the
  automatic handling of errors type 302 (relocated) and 401
  (authorization needed)."""

def addheader(self, *args):
  """Add a header to be used by the HTTP interface only
  e.g. u.addheader('Accept', 'sound/basic')"""

# sample comment

推荐答案

您可以添加以下行:

syn region Comment start=/"""/ end=/"""/

到你的 ~/.vim/after/syntax/python.vim.如果此文件不存在,您可以创建它.

to your ~/.vim/after/syntax/python.vim. You can create this file if it doesn't exists.

这篇关于突出显示 python 文档字符串作为注释(vim 语法突出显示)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆