diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-07-12 11:30:54 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-07-12 11:30:54 +1200 |
commit | 53ab5d55eb2ba2abf9a7959e8fd8283d3ec7e562 (patch) | |
tree | 29da697d76281a5488f2f9f584a04a3c5248caf7 | |
parent | First commit (diff) | |
download | vim-insert-timeout-53ab5d55eb2ba2abf9a7959e8fd8283d3ec7e562.tar.gz vim-insert-timeout-53ab5d55eb2ba2abf9a7959e8fd8283d3ec7e562.zip |
Remove autoload, trim down
-rw-r--r-- | plugin/insert_timeout.vim | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/plugin/insert_timeout.vim b/plugin/insert_timeout.vim index 2b127e9..36f63b6 100644 --- a/plugin/insert_timeout.vim +++ b/plugin/insert_timeout.vim @@ -9,20 +9,29 @@ if exists('g:loaded_insert_timeout') || &compatible finish endif -if v:version < 700 +if !has('autocmd') || v:version < 700 finish endif let g:loaded_insert_timeout = 1 +" Initialise 'updatetime' caching variable +let s:updatetime_save = &updatetime + +" Set update time to configured variable or default 20 seconds +function! s:SetUpdatetime() abort + let s:updatetime_save = &updatetime + let &updatetime = get(g:, 'insert_timeout_duration', 20000) +endfunction + +" Restore update time to globally configured variable +function! s:RestoreUpdatetime() abort + let &updatetime = s:updatetime_save +endfunction + " Set up actions in a group augroup insert_timeout autocmd! - - " Set and restore update time - autocmd InsertEnter * call insert_timeout#SetUpdatetime() - autocmd InsertLeave * call insert_timeout#RestoreUpdatetime() - - " Cancel insert mode if timeout reached + autocmd InsertEnter * call s:SetUpdatetime() + autocmd InsertLeave * call s:RestoreUpdatetime() autocmd CursorHoldI * stopinsert - augroup END |