Keep maps together

Sat, 24 Apr 2021 19:51:12 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Sat, 24 Apr 2021 19:51:12 -0500
changeset 897
760d4f0ca87b
parent 896
3c3d12500dd3
child 898
4bcbc5edab74

Keep maps together

.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,11 +87,3 @@ func! vimrc#SafeFilterFile(cmd)
     call delete(errors)
   endtry
 endfunc
-
-func! vimrc#on_lsp_buffer_enabled() abort
-  setl omnifunc=lsp#complete
-  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
@@ -117,6 +117,15 @@ noremap <leader>tm :Tabularize methods<C
 
 noremap <silent> <leader>a :call vimrc#AutoFmtToggle()<CR>
 
+" Maps that only apply when an LSP is available
+func! s:on_lsp_buffer_enabled() abort
+  setl omnifunc=lsp#complete
+  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
+
 " Commands & Aliases  {{{
 command! -nargs=+ CAlias call vimrc#CommandAlias(<f-args>)
 
@@ -339,7 +348,7 @@ let g:lsp_preview_doubletap = [function(
 
 augroup vim-lsp
   autocmd!
-  autocmd User lsp_buffer_enabled call vimrc#on_lsp_buffer_enabled()
+  autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
 
   if executable('rls')
     autocmd User lsp_setup call lsp#register_server({

mercurial