Popup Autocomplete

2 Points

Neni Neni

4 years ago

Autocomplete with words in buffer and dictionaries Credits: Maxime Boisvert https://gist.github.com/maxboisvert/a63e96a67d0a83d71e9f49af73e71d93

set completeopt=menuone,noinsert,noselect

set complete=.,b,k,w

inoremap <expr> <CR> pumvisible() ? "\<esc>o" : "\<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'

        call feedkeys("\<C-N>", 'n')
    end
endfun


" register of dictionaries

let g:dotfiles_dir = "~/path/to/dotfiles"
fun! AddDict(arquivo)
    let s:dict_dir = g:dotfiles_dir. "/vim/dicionarios"
    execute "setl dictionary+=".s:dict_dir."/".a:arquivo.".dict"
endfun

augroup dicionarios
    au BufEnter * call AddDict(&ft)
augroup END