2

Is there a way to temporarily disable/reenable the YouCompleteMe Plugin for vim? Syntastic has a nice way of doing so with the SyntasticToggleMode command (useful for when I know I'm writing code that won't compile and just don't want to see error messages at the moment).

I tried writing a quick Vim function that toggles the g:ycm_show_diagnostics_ui variable but it doesn't seem to work as I'd like even though the value of the variable changes.

Note: this works statically (i.e. if I set the g:ycm_show_diagnostics_ui variable to zero in my vimrc but doesn't work dynamically).

1
  • After you've sourced your plugins YCM is loaded. The only way to disable it to my knowledge would have to be a feature of YCM itself.
    – Tumbler41
    Commented May 23, 2018 at 18:21

2 Answers 2

2

After you toggle the value of g:ycm_show_diagnostics_ui, run :YcmRestartServer and then reload the file with :e.

1

Here's my toggle for turning off diagnostics and the completion menu:

"Toggle YouCompleteMe on and off with F3
function Toggle_ycm()
    if g:ycm_show_diagnostics_ui == 0
        let g:ycm_auto_trigger = 1
        let g:ycm_show_diagnostics_ui = 1
        :YcmRestartServer
        :e
        :echo "YCM on"
    elseif g:ycm_show_diagnostics_ui == 1
        let g:ycm_auto_trigger = 0
        let g:ycm_show_diagnostics_ui = 0
        :YcmRestartServer
        :e
        :echo "YCM off"
    endif
endfunction
map <F3> :call Toggle_ycm() <CR>

Even when I have YCM turned on, I don't want the cursor hover info popping up automatically, so I have a toggle set up for that as well. It still works even when the above toggle is off.

" turn off automatic YouCompleteMe cursor hover info
let g:ycm_auto_hover = ''

" toggle language hover info with F4
map <F4> <plug>(YCMHover)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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