如何自定义“评论标记"?在 Vim 中 [英] How can I customize "comment marker" in Vim

查看:32
本文介绍了如何自定义“评论标记"?在 Vim 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当设置 formatoptions 以包含 o 标志时,在注释行上按下 oO继承"领先的评论标记.

When setting the formatoptions to include the o flag, pressing o or O on a commented line will "inherit" the leading comment marker.

然而,对于 Stata,只有 \\ 被识别为有效注释".set formatoptions+=o 忽略了另外两种类型的注释.

However, for Stata, only \\ had been recognized as a "valid comment". The other two types of commenting had been ignored, by the set formatoptions+=o.

我可以命名多个前导字符/字符串作为 Vim 中的注释标记"吗?下面是如何在 Stata 的语法文件中定义注释行".

May I name multiple leading characters/strings to be the "comment marker" in Vim? Here goes how "comment lines" had been defined in the syntax file for Stata.

(来自 C:/vim/vimfiles/syntax/stata.vim)

" comments - single line
" note that the triple slash continuing line comment comes free
syn region stataStarComment  start=/^\s*\*/ end=/$/    contains=stataComment oneline
syn region stataSlashComment start="\s//"   end=/$/    contains=stataComment oneline
syn region stataSlashComment start="^//"    end=/$/    contains=stataComment oneline
" comments - multiple line
syn region stataComment      start="/\*"    end="\*/"  contains=stataComment

我没有看到 // 作为标记有什么特别之处,至少在语法文件中是这样.

I don't see anything special about the // as a marker, at least in the syntax file.

提前致谢.

推荐答案

您要查找的设置是 comments 设置.

The settings you are looking for is the comments settings.

因为 stata 文件似乎没有文件类型插件,所以没有人设置它并且它保持默认(这不是很好).

Since stata file don't appear to have a filetype plugin, nobody sets this and it stays at the default (which isn't very good).

由于stata的注释和c类似,我们可以看看c是如何处理注释的.在 $VIMRUNTIME/ftplugin/c.vim 中我们找到

Since stata comments are similar to c, we can look at how c handles the comments. In $VIMRUNTIME/ftplugin/c.vim we find

setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://

如果你把它添加到 ~/.vim/ftplugin/stata.vim 你应该有 c 样式注释添加到 stata 文件.(这似乎可以处理所有三种类型,即使前导 * 不是有效的 c 注释.)

If you add that to ~/.vim/ftplugin/stata.vim you should have c style comments added to stata files. (This seems to handle all three types even though the leading * isn't a valid c comment.)

相关帮助主题 :h 'comments':h format-comments.第二个帮助主题将解释 comments 的所有选项.

Relevant help topics :h 'comments' and :h format-comments. The second help topic will explain what all the options for comments.

这篇关于如何自定义“评论标记"?在 Vim 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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