Skip to content
Fangrui Song edited this page Aug 24, 2018 · 6 revisions

There are several implementations of language server protocol (client side) in Vim.

First, make sure you have ccls built following Getting Started and added to $PATH (e.g. via soft link).

vim-lsp

Install vim-lsp following its README.

Register ccls by adding the following into your ~/.vimrc or ~/.vim/vimrc:

" Register ccls C++ lanuage server.
if executable('ccls')
   au User lsp_setup call lsp#register_server({
      \ 'name': 'ccls',
      \ 'cmd': {server_info->['ccls']},
      \ 'root_uri': {server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'compile_commands.json'))},
      \ 'initialization_options': { 'cacheDirectory': '/tmp/ccls/cache' },
      \ 'whitelist': ['c', 'cpp', 'objc', 'objcpp', 'cc'],
      \ })
endif

Note you may want to customize cacheDirectory and whitelist of C/C++/... file suffixes to your taste.

Next, set up key bindings by adding the following to your ~/.vimrc or ~/.vim/vimrc:

" Key bindings for vim-lsp.
nn <silent> <M-d> :LspDefinition<cr>
nn <silent> <M-r> :LspReferences<cr>
nn <f2> :LspRename<cr>
nn <silent> <M-a> :LspWorkspaceSymbol<cr>
nn <silent> <M-l> :LspDocumentSymbol<cr>

Now it's good to go! Navigate to a C/C++/... project and test. Make sure you have compilation database in that project.

LanguageClient-neovim

Despite the name, LanguageClient-neovim does support vim besides neovim.

You are welcome to help provide vim spefici details here by editing the wiki. Meantime please refer to the Neovim page.

Clone this wiki locally