How to add C ++ 11 support for vim syntax plugin?

I use the syntax in my C ++ 11 project. When I edit in vim and save (: w), the syntax plugin gives me errors in every list of initializers {} and for every loop that explicitly contains the C ++ 11 functions that it absent.

I set the syntax using pathogen.

Here are two examples of the error I get in the initializer lists and for each loop (both C ++ 11 that compile fine):

error on initializer listserror on for each loop

+42
vim c ++ 11 syntastic
Aug 10 '13 at 5:00 a.m.
source share
5 answers

It turns out that there are a lot of parameters in the C ++ linter syntax (parser) that can be set on your .vimrc (unfortunately, I would like it to be project specific, e.g. .clang_complete).

To enable C ++ 11 standards and use the libC ++ library with clang (this is what my project uses), I added the following lines to my ~ / .vimrc

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

Now it works beautifully.

+77
Aug 14 '13 at 14:15
source share

I ran into the same problem and I insist on handling C ++ 98 and C ++ 11 separately . below is my solution:

create a file called gcc.vim under bundle / syntastic / syntax_checkers / cpp11 / and copy them into it:

 "============================================================================ "File: cpp11.vim "Description: Syntax checking plugin for syntastic.vim "Maintainer: Gregor Uhlenheuer <kongo2002 at gmail dot com> "License: This program is free software. It comes without any warranty, " to the extent permitted by applicable law. You can redistribute " it and/or modify it under the terms of the Do What The Fuck You " Want To Public License, Version 2, as published by Sam Hocevar. " See http://sam.zoy.org/wtfpl/COPYING for more details. " "============================================================================ if exists('g:loaded_syntastic_cpp11_gcc_checker') finish endif let g:loaded_syntastic_cpp11_gcc_checker = 1 if !exists('g:syntastic_cpp11_compiler') let g:syntastic_cpp11_compiler = executable('g++') ? 'g++' : 'clang++' endif if !exists('g:syntastic_cpp11_compiler_options') let g:syntastic_cpp11_compiler_options = '-std=c++11' endif let s:save_cpo = &cpo set cpo&vim function! SyntaxCheckers_cpp11_gcc_IsAvailable() dict return executable(expand(g:syntastic_cpp11_compiler)) endfunction function! SyntaxCheckers_cpp11_gcc_GetLocList() dict return syntastic#c#GetLocList('cpp11', 'gcc', { \ 'errorformat': \ '%-G%f:%s:,' . \ '%f:%l:%c: %trror: %m,' . \ '%f:%l:%c: %tarning: %m,' . \ '%f:%l:%c: %m,'. \ '%f:%l: %trror: %m,'. \ '%f:%l: %tarning: %m,'. \ '%f:%l: %m', \ 'main_flags': '-x c++ -fsyntax-only', \ 'header_flags': '-x c++', \ 'header_names': '\m\.\(h\|hpp\|hh\)$' }) endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({ \ 'filetype': 'cpp11', \ 'name': 'gcc' }) let &cpo = s:save_cpo unlet s:save_cpo " vim: set et sts=4 sw=4: 

which will make gcc-checker available (do you want another check? can you do similar things that I did for myself) for files with & filetype == 'cpp11' in vim. how to make your files automatically recongnized as cpp11 filetype in vim? just create a file called ext_detect.vim under ~ / .vim / ftdetect / with the following contents:

 au bufnewfile,bufread *.cpp11 set ft=cpp11 au bufnewfile,bufread *.cppx set ft=cpp11 

that way you can treat your * .cpp files as standard C ++ 98 and * .cpp11 or * .cppx as C ++ 11 standard separately, not only syntax checking, but also syntax highlighting (if you need cpp11 syntax highlighting support , this vim plugin will be useful, although not perfect).

+4
Apr 03 '14 at 3:38
source share

It has specific project options such as .clang_complete solution

You can set the path to the g: syntastic_cpp_config_file and g: syntastic_c_config_file files. The default value is .syntastic_cpp_config for C ++. Put the file in the root directory of the project and the compiler options inside it (one for each line)

for more details

+4
May 23 '14 at 7:28
source share

If you are using YouCompleteMe in addition to Syntastic, you need to modify the .ycm_extra_conf.py file. Change '-WC ++ 98-compat' to '-WnoC ++ 98-compat' one second.

I did not have to change Syntastic settings myself, although this may be due to the fact that I am using the compile_commands.json file.

here .

0
Feb 26 '14 at 2:04
source share

If you are using YouCompleteMe, you may need to change the ".ycm_extra_conf.py". Only change the flags: (path to the file ~ / .vim / bundle / YouCompleteMe / third_party / ycmd / cpp / ycm / .ycm_extra_conf.py);

  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
Aug 09 '16 at 15:42 on
source share



All Articles