I use a plugin called supertab( ervandew/supertab) that provide completion options. A menu automatically appears after I type 2 characters.

What I want to do, is to have a mapping that completes the phrase (using <c-x><c-n>) with one tap. What that means is that :

  • If we are not in keyword mode, switch to it, and select first match.

  • If a match is selected then complete it, select the next best option and wait on the menu.

I tried to write it, but it doesn't really work or rather, very buggy.

Anyone knows how to fix that, or what is wrong?

inoremap <c-f> <c-x><c-n>

function! DoCz()
    if pumvisible() 
        if complete_info()['mode']=='keyword'
            return complete_info()['selected'] ==-1 ? "\<c-r>=SuperTab('n')\<CR>" : "\<c-f>\<c-r>=SuperTab('n')\<CR>\<c-r>=SuperTab('p')\<CR>"
            return complete_info()['selected'] ==-1 ? "\<c-f>\<c-r>=SuperTab('n')\<CR>" : "\<c-f>\<c-r>=SuperTab('n')\<CR>"
        return "\<c-f>"

imap <expr> <c-z> DoCz() 

let g:SuperTabMappingForward = '<tab>'
let g:SuperTabMappingBackward = '<s-tab>'
let g:SuperTabDefaultCompletionType = "<c-x><c-n>"
let g:SuperTabContextDefaultCompletionType = "<c-x><c-n>" 
let g:SuperTabLongestEnhanced=1
let g:SuperTabLongestHighlight=1
  • I have added set completeopt=menuone (in addition to set completeopt+=noinsert ) and it greatly improve the situation. Although still a bit buggy. – eyal karni Feb 1 at 2:38
  • 1
    I started looking at this one, but I'm not so sure about what you're trying to accomplish and what issues you're encountering... You talk about being in keyword mode, so are you expecting to switch from other types of completion (e.g. line mode <c-x><c-l>) back to keyword mode and that's one of the cases you want to cover? Do you really want to just pick the first match (when there are more than one available)? What if you wanted a different one... Also not super sure of why SuperTab is that relevant here, you're using <c-x><c-n> (through <c-f>) in your mapping... – filbranden Feb 5 at 17:35
  • I am not super sure too. I had problems with c-x c-n directly, though I think that it would work and shouldn't matter much. It selects the first but I can switch to another one – eyal karni Feb 5 at 17:48
  • Do you think you can edit the question to give more details of what you're trying to accomplish, or demonstrate corner cases that are not working correctly? Perhaps a screenshot with the "before" situation, then which keys are pressed and what the "after" should be? I think that would help us figure out what to suggest here... – filbranden Feb 5 at 18:15

Your Answer

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

Browse other questions tagged or ask your own question.