Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

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 ''
endfunction
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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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