aboutsummaryrefslogtreecommitdiff
path: root/.vim/plugins/lsp.vim
diff options
context:
space:
mode:
authorgxlin <[email protected]>2021-06-07 19:54:10 +0800
committergxlin <[email protected]>2021-06-07 22:18:37 +0800
commit77af1ea1165d678a0b3953c43eaf7ddfc262ef68 (patch)
treea06c4dc22d5498e8668a859be8a340493f01b184 /.vim/plugins/lsp.vim
parentbd7d13c48383551cb4b81f9a62e3f38431b168c2 (diff)
downloaddotfiles-77af1ea1165d678a0b3953c43eaf7ddfc262ef68.tar.gz
dotfiles-77af1ea1165d678a0b3953c43eaf7ddfc262ef68.tar.bz2
dotfiles-77af1ea1165d678a0b3953c43eaf7ddfc262ef68.zip
Add lsp config for vim
Diffstat (limited to '.vim/plugins/lsp.vim')
-rw-r--r--.vim/plugins/lsp.vim39
1 files changed, 39 insertions, 0 deletions
diff --git a/.vim/plugins/lsp.vim b/.vim/plugins/lsp.vim
new file mode 100644
index 0000000..1a5704b
--- /dev/null
+++ b/.vim/plugins/lsp.vim
@@ -0,0 +1,39 @@
+Plug 'prabirshrestha/vim-lsp'
+
+if executable('gopls')
+ au User lsp_setup call lsp#register_server({
+ \ 'name': 'gopls',
+ \ 'cmd': {server_info->['gopls']},
+ \ 'allowlist': ['go'],
+ \ })
+endif
+
+function! s:on_lsp_buffer_enabled() abort
+ setlocal omnifunc=lsp#complete
+ setlocal signcolumn=no
+ if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
+ nmap <buffer> gd <plug>(lsp-definition)
+ nmap <buffer> gs <plug>(lsp-document-symbol-search)
+ nmap <buffer> gS <plug>(lsp-workspace-symbol-search)
+ nmap <buffer> gr <plug>(lsp-references)
+ nmap <buffer> gi <plug>(lsp-implementation)
+ nmap <buffer> gt <plug>(lsp-type-definition)
+ nmap <buffer> <leader>rn <plug>(lsp-rename)
+ nmap <buffer> [g <plug>(lsp-previous-diagnostic)
+ nmap <buffer> ]g <plug>(lsp-next-diagnostic)
+ nmap <buffer> K <plug>(lsp-hover)
+ inoremap <buffer> <expr><c-f> lsp#scroll(+4)
+ inoremap <buffer> <expr><c-d> lsp#scroll(-4)
+
+ let g:lsp_format_sync_timeout = 1000
+ autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync')
+
+ " refer to doc to add more commands
+endfunction
+
+augroup lsp_install
+ au!
+ " call s:on_lsp_buffer_enabled only for languages that has the server registered.
+ autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
+augroup END
+