0

Using the YouCompleteMe plugin, I'd like to be able to move my cursor over e.g. a function in all supported languages (e.g. JS), and use some keybinding to toggle the information dialog on/off. (At the moment, I have to wait a few seconds for the box to show; I'd prefer to control it explicitly).

Is this possible?

1
  • It could be that setting updatetime smaller would help; not manual, though – D. Ben Knoble Nov 19 '20 at 14:56
2

Add to your config:

nmap <silent> <leader>h <plug>(YCMHover)

I prefer K for that, but only for buffers/filetypes, where it makes sense:

let s:lsp_ft_maps = 'gdscript,go,python'

augroup ycm_settings | au!
    exe printf('au FileType %s call Ycm_mappings()', s:lsp_ft_maps)
augroup end

func! Ycm_mappings() abort
    nmap <silent><buffer> K <plug>(YCMHover)
    nnoremap <silent><buffer> gd :YcmCompleter GoTo<CR>
endfunc

UPD

This snippet creates an autocommand for filetypes listed in s:lsp_ft_maps that runs Ycm_mappings() function, that in turn creates buffer local mappings.

Buffer local mappings as name suggests are only available for a given buffer thus if you switch to another buffer where YCM doesn't have LSP functionality, original mappings would be in effect.

For example, K is used by vim to show a man page of a keyword under cursor, and for vim filetype (say your .vimrc), the same K is used to show vim help. With the snippet, it is preserved for non-lsp related buffers and shows YCM hover for buffers listed in s:lsp_ft_maps variable.

The same is with gd mapping -- it has original built-in functionality which this snippet overrides for some of filetypes.

2
  • Thanks. The first line seems to do what I want. I don't understand the rest of what you've written though. Could you please clarify? – Magnus Nov 19 '20 at 22:01
  • @Magnus see update. But if the first line works for you, don't bother :) – Maxim Kim Nov 20 '20 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.