Skip to content

Instantly share code, notes, and snippets.

@TerryChau
Forked from maxboisvert/.vimrc
Last active December 14, 2018 04:41
Show Gist options
  • Save TerryChau/c5ab83e47cbae02304c5f234ce6cb751 to your computer and use it in GitHub Desktop.
Save TerryChau/c5ab83e47cbae02304c5f234ce6cb751 to your computer and use it in GitHub Desktop.
Prevention of pressing of <C-P> again if the popup menu is already visible, and user <BS> characters then continue typing again.
" Add this to your vimrc to get a minimalist autocomplete pop
" Or use as a plugin : https://github.com/maxboisvert/vim-simple-complete
" Minimalist-TabComplete-Plugin
inoremap <expr> <Tab> TabComplete()
fun! TabComplete()
if getline('.')[col('.') - 2] =~ '\K' || pumvisible()
return "\<C-P>"
else
return "\<Tab>"
endif
endfun
" Minimalist-AutoCompletePop-Plugin
set completeopt=menu,menuone,noinsert
inoremap <expr> <CR> pumvisible() ? "\<C-Y>" : "\<CR>"
autocmd InsertCharPre * call AutoComplete()
fun! AutoComplete()
if v:char =~ '\K'
\ && getline('.')[col('.') - 4] !~ '\K'
\ && getline('.')[col('.') - 3] =~ '\K'
\ && getline('.')[col('.') - 2] =~ '\K' " last char
\ && getline('.')[col('.') - 1] !~ '\K'
if pumvisible()==0
call feedkeys("\<C-P>", 'n')
endif
end
endfun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment