I'm using basic autocompletion in Vim along with the Autocomplpop plugin, which automatically shows available completions when I start typing. Once I've typed enough to narrow down the list to the word I want, I'd like to be able to hit tab to choose that completion. With the script below, two tab presses are required instead of one, and I'm not sure why.

" Tab completion
" will insert tab at beginning of line,
" will use completion if not at beginning
set wildmode=list:longest,list:full
function! InsertTabWrapper()
    let col = col('.') - 1
    if !col || getline('.')[col - 1] !~ '\k'
        return "\<tab>"
        return "\<c-p>"
inoremap <Tab> <c-r>=InsertTabWrapper()<cr>
inoremap <S-Tab> <c-n>

2 Answers 2


Use return "\<c-y>" instead of return "\<c-p>".

  • Can you explain how and why this might work? … … … … … … … … … … … … … Please do not respond in comments; edit your answer to make it clearer and more complete.
    – Scott
    Mar 22, 2021 at 15:18

Use return "\<c-n>" instead of return "\<c-p>".

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.