vim YouCompleteMe without autoprompts
Last updated: Dec 8, 2023
YouCompleteMe without autoprompts
Summary
We can edit our .vimrc file to setup YouCompleteMe on vim so that the autoprompt drop down menu only appears when we tell it to and that the split window defintion disappears as soon as we make our selection.
The problem
YouCompleteMe is an excellent plugin for vim that suggests how to complete code using a drop down menu that automagically appears when you enter e.g. a class name.
I didn’t pay for this plugin and am grateful for all of the functionality that it provides. However, by default the prompts appears as you type without being requested.
I would prefer if the prompts only appear when I request, e.g. when I press the Tab key.
The second tweak I would like is to remove the helpful definition window that opens in a split window as you make your selection immediately after I make my selection. I found that this window remains open after I make my selection. Leaving insert mode makes it disappear, but I’d like it to go away after I’ve made my selection even if I stay in insert mode.
A solution
Having the prompts appear only by pressing the Tab key can be setup by adding the following lines to your .vimrc file:
" disable auto prompt
let g:ycm_auto_trigger=0
" select using Enter
let g:ycm_key_list_select_completion='<Enter>'
" Invoke using Tab
let g:ycm_key_invoke_completion='<Tab>'
Now, when you press the Tab key, the list of prompts appears. Select using the arrow key and pressing Enter.
To make the helpful definition window go away after I’ve made my selection even if I stay in insert mode can be achieved by adding this to your .vimrc file:
" close definition split window
let g:ycm_autoclose_preview_window_after_completion = 1