Skip to content

Instantly share code, notes, and snippets.

@Shougo
Created January 16, 2019 14:40
Show Gist options
  • Save Shougo/315af3b60882eaa30bffce2fbf42445a to your computer and use it in GitHub Desktop.
Save Shougo/315af3b60882eaa30bffce2fbf42445a to your computer and use it in GitHub Desktop.
" save this as complete_flicker.vim
" vim -u complete_flicker.vim -c "startinsert"
let s:months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
let s:cycle = 1
let s:last_tick = []
function! s:current_tick()
return [b:changedtick, getcurpos()]
endfunction
function! s:check_changes(...)
let l:current_tick = s:current_tick()
if s:last_tick != l:current_tick
let s:last_tick = l:current_tick
call s:on_changed()
endif
endfunction
function! s:start_check_changes_timer()
let s:last_tick = []
let s:check_change_timer = timer_start(30, function('s:check_changes'), {'repeat': -1})
endfunction
function! s:stop_check_changes_timer()
if exists('s:check_change_timer')
call timer_stop(s:check_change_timer)
unlet s:check_change_timer
endif
endfunction
function! s:on_changed()
if mode() != 'i'
return
endif
setlocal completeopt-=longest
setlocal completeopt+=menuone
setlocal completeopt-=menu
setlocal completeopt+=noselect
call complete(1, s:months[: s:cycle])
let s:cycle = (s:cycle + 3) % len(s:months)
endfunction
autocmd TextChangedI * call s:check_changes()
autocmd InsertEnter * call s:start_check_changes_timer()
autocmd InsertLeave * call s:stop_check_changes_timer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment