Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

vim

clang

I've already got Vim with YouCompleteMe plugin (compiled with semantic support for C-family languages), which I use for Python etc. Now I'd like to try it with C (I've never developed with C before, so I've got a slightly fuzzy idea about some details, like the necessary flags.)

To use YCM's semantic completion features with C, I need to provide it a .ycm_extra_conf.py file; the YCM user guide points to YCM's own .ycm_extra_conf.py as a reference (link).

Would the following (based on the aforesaid .ycm_extra_conf.py) produce "a minimal working setup" for C (to which I could then point g:ycm_global_ycm_extra_conf):

The flags:

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

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

Otherwise the example file would remain as-it-is. I believe that -isystem flags are strictly YCM-related, is that correct?

like image 463
kekkonen Avatar asked Aug 31 '14 15:08

kekkonen


1 Answers

I was searching for this too and seems here we haven't get a good solution. Even this is a very old question I hope this might 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, that long config file by the default bothers me so much. I should give credit for this post, http://cocoaspice.logdown.com/posts/302432-youcompleteme-toss-notes

like image 51
彭一粟 Avatar answered Sep 25 '22 23:09

彭一粟