Skip to content

Conditional mappings if LSP is running #4224

Discussion options

You must be logged in to vote

I have this in my config. Whenever a LSP is started the ALELSPStarted event is triggered so I have an autocommand that call the ALELSPMappings() to do some configurations.

Note this event is called everytime a LSP is started so make sure the method you call can be invoked several times without issues.

function ALELSPMappings()
  nnoremap <buffer> gk :ALEDocumentation<cr>
  nnoremap <buffer> gr :ALEFindReferences<cr>
  nnoremap <buffer> gd :ALEGoToDefinition<cr>
  nnoremap <buffer> gy :ALEGoToTypeDefinition<cr>
  nnoremap <buffer> gh :ALEHover<cr>
  setlocal omnifunc=ale#completion#OmniFunc
endfunction

augroup ALEMappings
  autocmd!
  autocmd User ALELSPStarted call ALELSPMappings()
augro…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@pbnj
Comment options

Answer selected by pbnj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants