Vim YouCompleteMe configuration

44,768

Solution 1

While the suggestions here might work in the beginning, I am not sure it's the proper way to go. According to YCM developer, whenever you start a project, you need a new .ycm_extra_conf.py file

From https://valloric.github.io/YouCompleteMe/#ubuntu-linux-x64-super-quick-installation

YCM looks for a .ycm_extra_conf.py file in the directory of the opened file or in any directory above it in the hierarchy (recursively); when the file is found, it is loaded (only once!) as a Python module. YCM calls a FlagsForFile method in that module which should provide it with the information necessary to compile the current file. You can also provide a path to a global .ycm_extra_conf.py file, which will be used as a fallback. To prevent the execution of malicious code from a file you didn't write YCM will ask you once per .ycm_extra_conf.py if it is safe to load. This can be disabled and you can white-/blacklist files. See the Options section for more details.

While you might only need to modify the compile flags from the vanilla .ycm_extra_conf.py, I feel it is advisable to create a new file for every project you start.

Solution 2

You need to navigate to ~/.vim/bundles/YouCompleteMe and run the installation script with --clang-completer, so do ./install.sh --clang-completer. After it finishes you should have support for C like languages.

You may also need to place let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py' in your ~/.vimrc.

Solution 3

I have installed with pathogen. I tried the above instructions with ./install.sh --clang-complete. After this, it did not work, and I indeed had to add the path. But it was different than in another reply here, namely

let g:ycm_global_ycm_extra_conf = '.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'

so there is an extra "third_party/ycmd" in the path.

Solution 4

I just wanted to add if you don't want to manually define a config file there is this neat little repository that will auto generate it. https://github.com/rdnetto/YCM-Generator

Solution 5

Everything that the folks here have said is correct. I just want to add that as of 2017, the "install.sh" script is deprecated. Now, you have to use the install.py script instead by typing

./install.py --clang-completer

Also, in your .vimrc file, instead of ".vim/bundle/blahblahblah", you'll need to add a "~/" in front of the address by adding:

let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py"

to your .vimrc file, to give it an absolute path from the Home directory so that Vim can find the ".ycm_extra_conf.py" file. Otherwise, you might experience some funny behavior.

Share:
44,768

Related videos on Youtube

mastergap
Author by

mastergap

Passionate Software Engineer and Software Architect. I have 4+ years experience in iOS development and 2+ years experience in backend development. I love node.js and Python. I like to keep learning new things and knowing new people. I'm a big fan of team working and I care a lot about good relationships.

Updated on February 16, 2020

Comments

  • mastergap
    mastergap about 4 years

    i just installed YouCompleteMe for Vim through vundle. It works, but it shows only the words contained in the current file. I want to use it to develop c++ programs, how can i configure it to show autocompletion from c++ headers file in /usr/include for example? Thanks a lot.

    • romainl
      romainl almost 11 years
      You need to build and install clang for semantic completion. Did you follow the installation process detailed in YCM readme?
    • mastergap
      mastergap almost 11 years
      Yes, I follow the instructions but i only get local autocompletion. In order i have installed YCM as a vundle bundle and I executed the install script located in the YCM directory. Is there some kind of configuration that I missed?
    • romainl
      romainl almost 11 years
      Did you do ./install.sh --clang-completer or ./install.sh?
    • mastergap
      mastergap almost 11 years
      I missed the --clang-completer option. Thanks a lot. Put an answer maybe, this way I can mark it as a correct solution.
    • Dilawar
      Dilawar almost 11 years
      @mastergap You can answer you own question.
  • Iman Mirzadeh
    Iman Mirzadeh about 9 years
    for new version of ycm it changed to : let g:ycm_global_ycm_extra_conf = ".vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_ext‌​ra_conf.py"
  • Arne
    Arne about 9 years
    for me it seems totally weired and unintuitive to define this config. Why do I need to set this config to a hidden file deep down in the plugin folder? For me this just feels wrong.
  • RaminS
    RaminS about 5 years
    Don't write comments as answers. Invest some time in the site and you will gain sufficient privileges to comment and vote on questions and answers.
  • Zoe stands with Ukraine
    Zoe stands with Ukraine about 5 years
    Newer versions use .py in general - install.sh is now install.py
  • Enlico
    Enlico almost 4 years
    The link is broken. It'd be nice if you could update it.
  • ljden
    ljden almost 4 years
    The edit queue is full, so putting the updated link here github.com/ycm-core/…