I viewed the posts and issues but can't find a solution, the best I found is to set g:ycm_min_num_of_chars_for_completion to a large number so YCM won't pop the completion window.
Here is my situation:
I'm working on some embedded projects which code is not supported by clang, and that made clang fail thus providing unusable completions. So I'm trying to use neocomplcache with those projects but use YCM on other standard c/c++ projects. But neocomplcache would disable itself if compltefunc was set by another plugin, so _setting g:ycm_min_num_of_chars_for_completion to a large number_ to disable YCM trick won't work.
Is it possible to add something like:YCMToggle which could enable/disable the plugin without a restart of vim?
Is it possible to add something like:YCMToggle which could enable/disable the plugin without a restart of vim?
I'm not sure that's doable. During setup, YCM sets a bunch of global options and settings, both in Vim and in other plugins (like Syntastic). There isn't really a way undo all of that.
We could build a half-assed toggle, but that would be even worse because people would then think that it actually undoes everything. I'd rather not have a feature than have a shitty one.
If it is impossible to enable/disable ycm without a vim restart, is it possible to do that via a vimrc config var? like let g:enable_ycm_at_startup = 0
That's already possible; put let g:loaded_youcompleteme = 1 in your vimrc and YCM won't load.
Thanks:)
if you using Vundle
you could use something like this
autocmd FileType c++ Bundle 'Valloric/YouCompleteMe'
and just replace the type you need instead of c++
@baronleonardo I don't think it will since YCM has an autocmd for the setup at VimEnter
@vheon I don't know that, but it works for me
I have found that letting b:ycm_largefile=1 disables the completion as well.
@baronleonardo
I use vundle to manage all the plugins include YCM.
I replace your command
autocmd FileType c++ Bundle 'Valloric/YouCompleteMe'
autocmd FileType c Bundle 'Valloric/YouCompleteMe'
autocmd FileType python Bundle 'Valloric/YouCompleteMe'
autocmd FileType shell Bundle 'Valloric/YouCompleteMe'
autocmd FileType php Bundle 'Valloric/YouCompleteMe'
instead of my old command
Plugin 'Valloric/YouCompleteMe'
But it seems doesn't work.
This feature request, which is commonly implemented by many plugins, would also be a nice addition for the plugin to play well with other plugins like https://github.com/terryma/vim-multiple-cursors, which is very slow when YCM is enabled. Such slowness could be fixed if just the YCM triggers could be turned on and off, not necessarily unloading the entire plugin.
@oblitum the slowness of vim-multiple-cursor is certainly about the insert mode autocmd and that is the reason that brought https://github.com/Valloric/YouCompleteMe/blob/master/autoload/youcompleteme.vim#L125 and https://github.com/Valloric/YouCompleteMe/blob/master/autoload/youcompleteme.vim#L134 to the codebase (https://github.com/Valloric/YouCompleteMe/commit/abdf38a055b8ed72d5f17b05565a5d5f5d6ed86e), so if vim-multiple-cursor calls DisableCursorMovedAutocommands and EnableCursorMovedAutocommands when it finishes it wouldn't be slow I think.
Thanks @vheon! I didn't know about this. Will take a look how to couple it with vim-multiple-cursor.
@vheon it seems to have improved a bit but diagnostics is still triggering and making it slow.
vim-multiple-cursors does have options for enabling/disabling stuff to do multiple cursor editing, I used this before:
" vim-multiple-cursors Setup {{{
function! Multiple_cursors_before()
let g:ycm_auto_trigger = 0
endfunction
function! Multiple_cursors_after()
let g:ycm_auto_trigger = 1
endfunction
" }}}
Now using this:
" vim-multiple-cursors Setup {{{
function! Multiple_cursors_before()
call youcompleteme#DisableCursorMovedAutocommands()
endfunction
function! Multiple_cursors_after()
call youcompleteme#EnableCursorMovedAutocommands()
endfunction
" }}}
Thanks, @Valloric "let g:loaded_youcompleteme = 1" does not work for my case.
My case is: some of my projects/folders has ycm support. Others don't. So when loading vim.exe, I want to disable ycm. Then later, for the projects which have ycm support, I want to turn ycm on.
What I tried is:
let g:loaded_youcompleteme = 1 on loading vim.exe
Then later, when I open the file of the project/folders which have ycm support, I tried
let g:loaded_youcompleteme = 0
or
unlet g:loaded_youcompleteme
Then
execute "YcmRestartServer"
None of them can turn on YCM. YcmRestartServer does not respect new setting of g:loaded_youcompleteme, which seems a bug to me.
Any suggestion? Thanks.
Is there any way to do this by editing the project's .ycm_extra_conf.py? Maybe putting wrong configs or something so that YCM cannot load for that particular project?
In my case, sometimes the libraries you are using are pretty heavy (i.e. tensorflow, numpy, pytorch, etc.) , so when you start with a main method (i.e. torch.nn.) then there are many methods available and everything becomes laggy. It would be ideal if I could have it such that, when I'm ready for completion help, I press a shortcut and then suggestions get loaded
Just as a note: I remember doing this by simply messing up the .ycm_extra_conf.py of the project I was in. If the file is broken, then YCM won't load.
There is no "cleaner" alternative?? I find autocompletion useful, but only when I need it, otherwise I find it to be distracting.
Jupyter notebooks handles it well imo, suggestions only come up when you hit tab.
@jerpint See the g:ycm_auto_trigger option.
In my case, sometimes the libraries you are using are pretty heavy (i.e. tensorflow, numpy, pytorch, etc.) , so when you start with a main method (i.e. torch.nn.) then there are many methods available and everything becomes laggy.
By laggy, do you mean the editor become unresponsive? That shouldn't happen because the computation is done in a separate process.
Just as a note: I remember doing this by simply messing up the .ycm_extra_conf.py of the project I was in. If the file is broken, then YCM won't load.
That's not true. The ycmd server will still be started. What will happen is that you won't get semantic completion at all in C/C++/Python projects which I doubt is something you want. In fact, this will be annoying because the error in the .ycm_extra_conf.py file will constantly be reported on the command line. In other words, don't do that.
By laggy, do you mean the editor become unresponsive? That shouldn't happen because the computation is done in a separate process
Yes, the editor becomes unresponsive, it takes time before the suggestions pop up, if you type meanwhile it still works but you dont see it until the window loads. I should note that loading the window is what takes time, once the window is loaded everything works alright
The command let g:ycm_min_num_of_chars_for_completion = 99 would do what I want, but it doesn't seem to work when I add it to my .vimrc nor when I type it directly in vim. Could virtualenvs be to blame?
Are you sure you are using the latest version of YCM? What's the output of :YcmDebugInfo when editing a Python file?
The command let g:ycm_min_num_of_chars_for_completion = 99 would do what I want, but it doesn't seem to work when I add it to my .vimrc nor when I type it directly in vim. Could virtualenvs be to blame?
So you want to disable the identifier completions but not the semantic ones? If you are setting the option in Vim, you need to restart the server with :YcmRestartServer for the option to take effect.
@micbou I may remember incorrectly, although I do remember clearly being able to do that. Maybe I didn't break the file, but I passed incorrect options to the compiler. Or maybe I just changed the language with the -x option to something I wasn't using. In either case, in the end I was able to activate/deactivate YCM per-project, without needing to mess up my main .vimrc file.
And I think this also allowed to enable/disable YCM by using the restart server command, after fixing the file again. So it is as close as I could manage to a button to turn off YCM at will.
Most helpful comment
That's already possible; put
let g:loaded_youcompleteme = 1in your vimrc and YCM won't load.