I use the following mapping to initiate keyword completion, followed by user defined completion:

inoremap <expr> <c-n> pumvisible() ? "\<c-x>\<c-o>" : "\<c-n>"

How can I rewrite this mapping so that repeatedly pressing <c-n> results in the cycling of keyword and user defined completion?


I'm not sure when exactly you would initiate the cycling (as you typically use <C-N> to both trigger and go through the list of matches), but the key to implementing this is via a boolean flag stored in a variable. To be able to use :let to toggle this, you need to move from an inline expression to a function (which still returns the chosen completion key).

inoremap <expr> <c-n> TriggerOrToggleCompletion()
function! TriggerOrToggleCompletion()
| improve this answer | |
  • I use <c-j> and <c-k> when pumvisble() to move through the list. I will look in to this, thank you. – user489 Mar 18 '15 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy