Search code examples
vimautocompletevim-pluginneovimyoucompleteme

Vim's Ctrl-n shortcut doesn't work until I press ESC and enter insert mode again


The vim's autocompletion keybinding <c-n> doesn't work properly in insert mode. When edit file and press <c-n>, nothing happens to me.

If I return back to normal mode by pressing ESC and then reenter insert mode, this shortcut works but can only autocomplete one time. Consequence <c-n> operations get no respond unless I repeat the ESC, i procedure.

Maybe, it is YCM that makes <c-n> shortcut invalid. I tried disabling YCM then everything works OK.


Solution

  • After check the manual of YCM, I got this option:

    The g:ycm_filetype_blacklist option This option controls for which Vim filetypes (see :h filetype) should YCM be turned off. The option value should be a Vim dictionary with keys being filetype strings (like python, cpp etc) and values being unimportant (the dictionary is used like a hash set, meaning that only the keys matter).

    See the g:ycm_filetype_whitelist option for more details on how this works.

    Then, append the file type which you want to enable <c-n> shortcut to the end of the default blacklist, for example, gitcommit file type.

    let g:ycm_filetype_blacklist = {
        \ 'tagbar' : 1,
        \ 'qf' : 1,
        \ 'notes' : 1,
        \ 'markdown' : 1,
        \ 'unite' : 1,
        \ 'text' : 1,
        \ 'vimwiki' : 1,
        \ 'pandoc' : 1,
        \ 'infolog' : 1,
        \ 'mail' : 1,
        \ 'gitcommit': 1
        \}
    

    Now, you can active <c-n> and enjoy it.