Vim + YouCompleteMe + C: minimal .ycm_extra_conf.py?

I already have Vim with the YouCompleteMe plugin (compiled with semantic support for C-family languages), which I use for Python, etc. Now I would like to try it with C (I have never developed from C to, so I have a little fuzzy idea about some details, for example about the necessary flags.)

To use the YCM semantic completion functions with C, I need to provide it with the .ycm_extra_conf.py file; The YCM user manual points to the YCM .ycm_extra_conf.py native symbol as a link ( link ).

Will the following (based on the above .ycm_extra_conf.py ) create a "minimum working setting" for C (which I could then point to g:ycm_global_ycm_extra_conf ):

flags :

 flags = [ '-Wall', '-Wextra', '-Werror', '-std=c11', '-x', 'c' ] 

and FlagsForFile without the FlagsForFile line final_flags.remove( '-stdlib=libc++' ) .

Otherwise, the sample file will remain as-is-is. I believe the -isystem flags -isystem strictly related by YCM, is this true?

+6
source share
3 answers

I also searched for this, and it seems that we do not have a good solution. Even this is a very old question, I hope this can help someone. The following works for me:

 import os import ycm_core flags = [ '-Wall', '-Wextra', '-Werror', '-Wno-long-long', '-Wno-variadic-macros', '-fexceptions', '-ferror-limit=10000', '-DNDEBUG', '-std=c99', '-xc', '-isystem/usr/include/', ] SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', ] def FlagsForFile( filename, **kwargs ): return { 'flags': flags, 'do_cache': True } 

By the way, this long default configuration file bothers me so much. I have to pay tribute to this post, http://cocoaspice.logdown.com/posts/302432-youcompleteme-toss-notes

+4
source

To give you a working example, here is the configuration I use for Arduino projects.

https://github.com/WeAreLeka/Bare-Arduino-Project/blob/master/.ycm_extra_conf.py

In flags I put all the Arduino libraries provided by the IDE, and I needed to compile my code.

I also wrote a small function to find other libraries in my /lib directory that I use in my project and add them automatically to flags . This is line 57 .

This is useful if you use a lot of libs and do not want to change your conf file every time.

Without -I /path/to/lib/folder you will not get autocomplete.

Hope this helps :)

+2
source

Nothing is completely valid if the sources can be compiled simply by clang++ -c source (c vs. C ++ is determined from the extension). YCM happily completes the scratch tests created in arbitrary directories for me.

-xc not required. If the source has the extension .c or .h , it is considered C and has the extension .c , .cc , .cpp , .cxx , .h , .hh , .hpp or .hxx it is assumed that C ++. Only if you have C ++ headers only with .h , you need -x c++-header .

The new clang (4.9) already defaults to c11 and C ++ 11, so you don't need it either.

Therefore you only need the -I flags, and warnings are useful.

+1
source

Source: https://habr.com/ru/post/974615/


All Articles