mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 00:55:08 +00:00
add vim-lsp
parent
d16549734f
commit
c34494d941
31
Vim.md
31
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 <silent> <M-d> :LspDefinition<cr>
|
||||
nn <silent> <M-r> :LspReferences<cr>
|
||||
nn <f2> :LspRename<cr>
|
||||
```
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user