diff --git a/Vim.md b/Vim.md index 0e5037a..5a37edf 100644 --- a/Vim.md +++ b/Vim.md @@ -1,7 +1,38 @@ 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](https://github.com/prabirshrestha/vim-lsp) following its README. + +Register ccls by adding the following into your `~/.vimrc` or `~/.vim/vimrc`: + +```vim +" 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`: + +```vim +" Key bindings for vim-lsp. +nn :LspDefinition +nn :LspReferences +nn :LspRename +``` + +Now it's good to go! Navigate to a C/C++/... project and test. Make sure you have [compilation database](https://github.com/MaskRay/ccls/wiki/compile_commands.json) in that project. ## LanguageClient-neovim