如何从Vim语法高亮中排除C ++原始字符串文字? [英] How to exclude C++ raw string literals from syntax highlighting in Vim?
问题描述
老实说,原始字符串文字是C ++语言的重要补充.但是(按预期)编辑人员很难正确显示这些文字.
Quite honestly, raw string literals are a great addition to the C++ language. But (as expected) editors have a hard time to properly display those literals.
我正在使用Vim 7.4,开箱即用的原始字符串文字完全破坏了语法突出显示.例如在
I am using Vim 7.4 and out-of-the-box raw string literals completely break the syntax highlighting. For example in
char const txt[] = R"(printf(")";
第二个'('在vim中以红色突出显示.
the 2nd '(' is highlighted red in vim.
类似
char const txt2[] = R"( "{{" )";
打破了花括号和基于语法的自动识别的突出显示,依此类推.
breaks the highlighting of curly braces and the syntax based auto-ident - and so on.
首先,我很乐意让Vim在突出显示语法时忽略 R(
和)"
之间的所有内容.
For a start I would be happy to have Vim ignore everything between R"(
and )"
when doing syntax highlighting.
但是请注意,原始字符串文字很灵活-第一个/最后一个双引号/括号之间允许任意匹配的字符串,例如
But note that raw string literals are flexible - arbitrary matching strings are allowed between the first/last double-quote/brace pair, e.g.
R"abcd()")")abcd"
也是有效的原始字符串文字,可以对其进行编码
is also a valid raw string literal which encodes
)")"
有关语法的一般定义,另请参见cppreference链接.
See also the cppreference link for a general definition of the syntax.
因此,我的问题是如何配置Vim,以便正确识别C ++原始字符串文字.
Thus my question how to configure Vim such that C++ raw string literals are properly recognized.
Vim似乎已经包含了一些功能,可以适当地突显主机语言中嵌入的语言片段(例如,用于编译器-编译器源文件).也许它们也可以用于原始字符串文字大小写情况?
Vim already seems to include some facilities to properly synatx highlight language fragments embedded in a host language (e.g. for compiler-compiler source files). Perhaps they can be used for the raw string literal case as well?
推荐答案
只需添加 cpp-vim 作为插件.我在 pull-request#14 中添加了对较新的字符串文字的严格支持.
Just add cpp-vim as a plugin. I have added strict support for newer string literals in pull-request #14.
这就是您得到的: http://bl.ocks.org/anonymous/raw/9442865
cpp-vim也增加了对其他C ++ 11内容的支持.
cpp-vim adds support for other C++11 stuff too.
这篇关于如何从Vim语法高亮中排除C ++原始字符串文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!