-3

Question Edited

I mostly code in C and have been using vscode. I recently decided to try out vim and am trying to get code autocompletion to something resembling vscode. Youcompleteme is popular vim plugin. On using it I noticed that the code completion out of the box is really primitive and only completed the symbols in the current file and inbuild libraries.

My software versions

WSL Ubuntu 20.04.
GCC: gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
vim: VIM - Vi IMproved 8.1 (2018 May 18, compiled Apr 15 2020 06:40:31) Included patches: 1-2269

I installed it with python3 install.py --clangd-completer but its only partially suggesting symbols.

How do I get the autocomplete engine to show me symbols from my header files across my project?

1 Answers1

0

I am providing an answer my own question so that others may find this. Here is how you get YouCompleteMe to autocomplete their C code in vim across your project.

python3 install.py --clangd-completer

YCM claims that using will enable the above command to install YCM will enable C semantic completion but it did not do so in my case. The code completion only worked for inbuilt C libraries and for the current file being worked on.

Versions I am using:

WSL Ubuntu 20.04.
GCC: gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
vim: VIM - Vi IMproved 8.1 (2018 May 18, compiled Apr 15 2020 06:40:31) Included patches: 1-2269

Its current behavior is to only complete standard library files and the symbols from the current file which is obviously not enough. This is happening because the clangd that YCM is bundling during installation is not up-to-date and therefore doesnt have the dynamic indexing support they claim to have. Fortunately, we have the ability to provide it YCM with our own clangd binary which it will use for code completion from files across your project.

In order to do this, you must download clang 13 from the here

On downloading and extracting it, you must add the path of <clang-for-your-respective-distribution>/bin/clangd to your PATH.

Now add the following settings to your vimrc file that allow it to use your clangd over the bundled one.

let g:ycm_clangd_uses_ycmd_caching=0 let g:ycm_clangd_binary_path='/home/shiva/clang+llvm-13.0.0-x86_64-linux-gnu-ubuntu-20.04/bin/clangd'

save and source your vimrc. Enjoy full code completion.