DEV Community

Roby Cigar
Roby Cigar

Posted on

4 3

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay