Skip to content

Instantly share code, notes, and snippets.

@qstrahl
Last active February 24, 2024 06:43
Show Gist options
  • Save qstrahl/7795524 to your computer and use it in GitHub Desktop.
Save qstrahl/7795524 to your computer and use it in GitHub Desktop.
Super lightweight autocomplete using vim's built-in <C-n> completion
set cot=menu,menuone
ino <BS> <BS><C-r>=getline('.')[col('.')-3:col('.')-2]=~#'\k\k'?!pumvisible()?"\<lt>C-n>\<lt>C-p>":'':pumvisible()?"\<lt>C-y>":''<CR>
ino <CR> <C-r>=pumvisible()?"\<lt>C-y>":""<CR><CR>
ino <Tab> <C-r>=pumvisible()?"\<lt>C-n>":"\<lt>Tab>"<CR>
ino <S-Tab> <C-r>=pumvisible()?"\<lt>C-p>":"\<lt>S-Tab>"<CR>
augroup MyAutoComplete
au!
au InsertCharPre * if
\ !exists('s:complete') &&
\ !pumvisible() &&
\ getline('.')[col('.')-2].v:char =~# '\k\k' |
\ let s:complete = 1 |
\ noautocmd call feedkeys("\<C-n>\<C-p>", "nt") |
\ endif
au CompleteDone * if exists('s:complete') | unlet s:complete | endif
augroup END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment