From 77af1ea1165d678a0b3953c43eaf7ddfc262ef68 Mon Sep 17 00:00:00 2001 From: gxlin Date: Mon, 7 Jun 2021 19:54:10 +0800 Subject: Add lsp config for vim --- .vim/plugins/leaderf.vim | 2 +- .vim/plugins/lsp.vim | 39 +++++++++++++++++++++++++++++++++++++++ .vim/plugins/misc.vim | 2 -- .vim/plugins/vista.vim | 9 +++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 .vim/plugins/lsp.vim create mode 100644 .vim/plugins/vista.vim (limited to '.vim/plugins') diff --git a/.vim/plugins/leaderf.vim b/.vim/plugins/leaderf.vim index 584322a..116a994 100644 --- a/.vim/plugins/leaderf.vim +++ b/.vim/plugins/leaderf.vim @@ -19,4 +19,4 @@ xnoremap gf :=printf("Leaderf! rg -F -e %s ", leaderf#Rg#visual()) noremap go :Leaderf! rg --recall let g:Lf_WorkingDirectoryMode = 'AF' -let g:Lf_RootMarkers = ['.project', '.root', '.svn', '.git', '.hg'] +let g:Lf_RootMarkers = ['.project', '.root', '.svn', '.git', '.hg', '.projectile'] 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 gd (lsp-definition) + nmap gs (lsp-document-symbol-search) + nmap gS (lsp-workspace-symbol-search) + nmap gr (lsp-references) + nmap gi (lsp-implementation) + nmap gt (lsp-type-definition) + nmap rn (lsp-rename) + nmap [g (lsp-previous-diagnostic) + nmap ]g (lsp-next-diagnostic) + nmap K (lsp-hover) + inoremap lsp#scroll(+4) + inoremap 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 + diff --git a/.vim/plugins/misc.vim b/.vim/plugins/misc.vim index 5067f5a..f79b438 100644 --- a/.vim/plugins/misc.vim +++ b/.vim/plugins/misc.vim @@ -1,7 +1,5 @@ Plug 'scrooloose/nerdtree', {'on': 'NERDTreeToggle'} -map :NERDTreeToggle - Plug 'skywind3000/asyncrun.vim' let g:asyncrun_open = 6 " the number of lines of quickfix window diff --git a/.vim/plugins/vista.vim b/.vim/plugins/vista.vim new file mode 100644 index 0000000..02264b9 --- /dev/null +++ b/.vim/plugins/vista.vim @@ -0,0 +1,9 @@ +Plug 'liuchengxu/vista.vim' + +let g:vista_default_executive = 'ctags' + +let g:vista_executive_for = { + \ 'go': 'vim_lsp', + \ } + +nnoremap s :Vista -- cgit v1.2.3