如何让 vim 突出显示任何后面不跟有 C++ 的 {样式注释,还是两个换行符?
我想为任何不遵循以下模式之一的左大括号创建一个匹配模式:
{\n\n
{\s*\/\/.*\n\( \s*\/\/.*\)\?\n
更普遍的问题是突出显示工作中违反编码规范的情况,这会强制在 {
后面添加一个空行
澄清,我我正在寻找这个来捕获如下代码:
if (foo) {
this_is_bad____no_blank_line_above();
} else {this_is_worse();}
while (1) { //This comment is allowed
//This one too
theres_nothing_wrong_with_this();
}
if (foo) {
....//<-- Ideally we could mark this as bad, due to the spaces here
otherwise_perfectly_good();
}
我真正需要的是: {\(\n\n\|\s*\/\/.*\n\(\s*\/\/ .*\)\?\n\)\!
其中,虚构符号 \!
表示“与这两个选项均不匹配”。我看到了一种针对单个字符执行此操作的方法,但不适用于较长的字符串。
I would like to create a match pattern for any opening brace that does not follow one of these patterns:
{\n\n
{\s*\/\/.*\n\(\s*\/\/.*\)\?\n
The more general problem is highlighting violations of a coding spec at work, which enforces a blank line following {
Clarification, I'm looking for this to catch code like the following:
if (foo) {
this_is_bad____no_blank_line_above();
} else {this_is_worse();}
while (1) { //This comment is allowed
//This one too
theres_nothing_wrong_with_this();
}
if (foo) {
....//<-- Ideally we could mark this as bad, due to the spaces here
otherwise_perfectly_good();
}
What I really need is: {\(\n\n\|\s*\/\/.*\n\(\s*\/\/.*\)\?\n\)\!
Where the made-up symbol \!
means "Does not match either of these two options". I see a way of doing that for individual characters, but not for a longer string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
找到了:
我正在寻找
\@!
记录在
:h /\@!
Found it:
I was looking for
\@!
Documented at
:h /\@!
将以下内容添加到 .vimrc 文件的末尾:
第一行定义新的突出显示样式(红底黑字),下一行尝试查找其后包含非注释内容的任何大括号,并将突出显示应用于他们。
Add the following to the end of your .vimrc file:
The first line defines a new highlight style (black on red) and the next line tries to find any curly braces that have content after them which aren't comments and applies the highlighting on them.