Is there a C++11 syntax file for vim?

C++VimC++11

C++ Problem Overview


In particular, the display of initialization lists is really bad:

vector<int> v({1,2,3});

will highlight the curly braces in red (denoting an error).

C++ Solutions


Solution 1 - C++

As an alternative, you can use

let c_no_curly_error=1

in your .vimrc file so that vim doesn't tag {} as error in ().

Solution 2 - C++

There is now a C++11 script from http://www.vim.org/scripts/script.php?script_id=3797, which no longer mark the braces inside parenthesis as error.

Solution 3 - C++

If you use Syntastic, add this to your .vimrc (or .vimrc.local).

let g:syntastic_cpp_compiler_options = ' -std=c++11'

Syntastic shows errors for code written in multiple languages. Each language has a "checker" which is a wrapper to execute an external program. The external program for the c++ checker is g++. The c++ checker can pass compiler options to g++ and can be configured.

https://github.com/scrooloose/syntastic/wiki/C--:---gcc

If you want to use clang++, you can use these options

let g:syntastic_cpp_compiler = 'clang++'
let g:syntastic_cpp_compiler_options = ' -std=c++11 -stdlib=libc++'

Solution 4 - C++

use uniform initialization instead of the old () constructor

vector v {1,2,3};

Solution 5 - C++

As far as I know, there is a work in progress for that, see here at the vim_dev mail list.

Solution 6 - C++

An improved patch for C++11 support has been sent to the mailing list: https://groups.google.com/forum/?fromgroups#!topic/vim_dev/ug_wmWQqyGU

Solution 7 - C++

You can also configure this in a local syntastic config file.

Drop a .syntastic_cpp_config file in your project root and give it the compiler arguments one per line (I also have include paths for the Loki library as an example):

-std=c++11
-Ilib/loki/include
-Ilib/loki_book/include

Solution 8 - C++

If you use YouCompleteMe,you can change '.ycm_extra_conf.py'.like this:(file path~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py) ;

only change flags

flags = [
'-std=c++11',
'-O0',  
'-Werror', 
'-Weverything', 
'-Wno-documentation', 
'-Wno-deprecated-declarations', 
'-Wno-disabled-macro-expansion', 
'-Wno-float-equal', 
'-Wno-c++98-compat', 
'-Wno-c++98-compat-pedantic', 
'-Wno-global-constructors', 
'-Wno-exit-time-destructors', 
'-Wno-missing-prototypes', 
'-Wno-padded', 
'-Wno-old-style-cast',
'-Wno-weak-vtables',
'-x', 
'c++', 
'-I', 
'.', 
'-isystem', 
'/usr/include/', 

]

Solution 9 - C++

I have searched the other proposals about C++11 syntax file of VIM and they are old and not maintained. Anyway, recent distributions of Vim have good syntax files already. Sometimes they are updated though and official source of syntax files is here: https://github.com/vim-jp/vim-cpp

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNeil GView Question on Stackoverflow
Solution 1 - C++thrustView Answer on Stackoverflow
Solution 2 - C++kennytmView Answer on Stackoverflow
Solution 3 - C++Chad SkeetersView Answer on Stackoverflow
Solution 4 - C++KekeView Answer on Stackoverflow
Solution 5 - C++TarantulaView Answer on Stackoverflow
Solution 6 - C++RicardoView Answer on Stackoverflow
Solution 7 - C++LostSaladView Answer on Stackoverflow
Solution 8 - C++MulticsYinView Answer on Stackoverflow
Solution 9 - C++RadoView Answer on Stackoverflow