DEV Community

Roby Cigar
Roby Cigar

Posted on

How to Install C++ Language Server on VIM

In this tutorial i'll show you how to install language server on vim/nvim.

1. Firstly, you need to install the ccls

sudo pacman -S ccls or sudo apt install ccls.

2. Install coc.nvim

Inside vim config(put this following line inside .vimrc or ~/.config/nvim/init.vim).

Plug 'neoclide/coc.nvim', {'branch': 'release'}
Enter fullscreen mode Exit fullscreen mode

3. Set coc.nvim configuration

Open vim, go to insert mode(press esc) and type :CocConfig, then a popup file will be shown and then copy paste the following script:

"languageserver": {
  "ccls": {
    "command": "ccls",
    "filetypes": ["c", "cc", "cpp", "c++", "objc", "objcpp"],
    "rootPatterns": [".ccls", "compile_commands.json", ".git/", ".hg/"],
    "initializationOptions": {
        "cache": {
          "directory": "/tmp/ccls"
Enter fullscreen mode Exit fullscreen mode

4. Here's some of the features you can try:

  • Tab for completion
  • <cr> to choose first completion item
  • gd to jump to definition
  • gr for references
  • gy for type definition
  • K for documentation
  • <leader>rn for renaming
  • if, ic for func/class selection in visual mode
  • <space>a to list diagnostics
  • [g and ]g to go prev/next in diagnostics

Discussion (0)