Set up maps when LSP enabled

Wed, 20 May 2020 04:52:29 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Wed, 20 May 2020 04:52:29 -0500
changeset 862
279abee5d0e8
parent 861
8e6131020307
child 863
c1b4166611ed

Set up maps when LSP enabled

.vim/autoload/vimrc.vim file | annotate | diff | comparison | revisions
.vimrc file | annotate | diff | comparison | revisions
--- a/.vim/autoload/vimrc.vim
+++ b/.vim/autoload/vimrc.vim
@@ -87,3 +87,12 @@ func! vimrc#SafeFilterFile(cmd)
     call delete(errors)
   endtry
 endfunc
+
+func! vimrc#on_lsp_buffer_enabled() abort
+    setl omnifunc=lsp#complete
+    setl signcolumn=yes
+    nmap <buffer> <F9> <plug>(lsp-hover)
+    nmap <buffer> gd   <plug>(lsp-definition)
+    nmap <buffer> ]d   <plug>(lsp-next-diagnostic)
+    nmap <buffer> [d   <plug>(lsp-previous-diagnostic)
+endfunc
--- a/.vimrc
+++ b/.vimrc
@@ -335,9 +335,9 @@ let g:lsp_diagnostics_echo_cursor = 1
 
 augroup vim-lsp
   autocmd!
+  autocmd User lsp_buffer_enabled call vimrc#on_lsp_buffer_enabled()
 
   if executable('rls')
-    autocmd FileType rust setlocal omnifunc=lsp#complete
     autocmd User lsp_setup call lsp#register_server({
       \ 'name': 'rls',
       \ 'cmd': {server_info->['rustup', 'run', 'stable', 'rls']},
@@ -346,7 +346,6 @@ augroup vim-lsp
   endif
 
   if executable('gopls')
-    autocmd FileType go setlocal omnifunc=lsp#complete
     autocmd User lsp_setup call lsp#register_server({
       \ 'name': 'gopls',
       \ 'cmd': {server_info->['gopls']},
@@ -355,7 +354,6 @@ augroup vim-lsp
   endif
 
   if executable('nimlsp')
-    autocmd FileType nim setlocal omnifunc=lsp#complete
     autocmd User lsp_setup call lsp#register_server({
       \ 'name': 'nimlsp',
       \ 'cmd': {server_info->['nimlsp']},

mercurial