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).