What I want is the following:

  1. Pressing TAB completes the current word I'm writing with the longest common prefix, and nothing more. I don't want to cycle through any options either, pressing TAB again should return me to the original string preferably, or do nothing if that's not possible.

  2. Pressing CTRL + SPACE should pop up a menu showing all possible completions like the default vim.

Is this possible? I've found cycling through options / opening menus is extremely distracting for me while programming, and encourages the behaviour to keep cycling and hope that the completion I'm looking for is there.


For the longest common text, use

:set completeopt+=longest

To avoid showing any other matches:

:set completeopt-=menu

<C-N> / <C-P> will still show the other matches; learn to use <C-E> to stop completion and go back to the originally typed text.

For the mapping:

function s:EnableCompleteMenu()
    set completeopt+=menu
    return ''
inoremap <expr> <SID>EnableCompleteMenu s:EnableCompleteMenu()
inoremap <script> <C-Space> <SID>EnableCompleteMenu<C-N>

You could also use <C-P> for showing matches in the other direction. Note that the <C-Space> mapping probably only works in GVIM. If you want to use that together with the commands from above, you need to write a similar wrapper (with :set completeopt-=menu) and overload the other completion commands (<C-N>, etc.) with it.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.