64

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).

2

9 Answers 9

36

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 ().

0
32

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.

1
25

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++'
2
  • 1
    Please use the actual clang versioning scheme to denote clang versions, not what apple does with it.
    – Cubic
    Commented May 19, 2013 at 23:11
  • 1
    Pretty sure the question is not about linters or semantic checkers or compilers failing, it is about Vim's native syntax grammar not accepting initializer lists inside parens.
    – Steven Lu
    Commented May 16, 2015 at 19:01
9

use uniform initialization instead of the old () constructor

vector v {1,2,3};

0
6
+100

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

4

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

1
  • Thanks for the update. Do you know if any distros picked it up? Or isn't it in upstream Vim yet?
    – sehe
    Commented Sep 19, 2013 at 9:42
2

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
1

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/', 

]

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.