How to exclude C++ raw string literals from syntax highlighting in Vim?

c++, c++11, rawstring, vim, vim-syntax-highlighting

Solution

Just add cpp-vim as a plugin. I have added strict support for newer string literals in pull-request #14.

This is what you get: http://bl.ocks.org/anonymous/raw/9442865

cpp-vim adds support for other C++11 stuff too.

Problem

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. 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(")"; ``` the 2nd '(' is highlighted red in vim. Something like ``` char const txt2[] = R"( "{{" )"; ``` breaks the highlighting of curly braces and the syntax based auto-ident - and so on. 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 ``` )")" ``` See also the cppreference link for a general definition of the syntax. Thus my question how to configure Vim such that C++ raw string literals are properly recognized. 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?

Original source