aboutsummaryrefslogtreecommitdiff
path: root/autoload/insert_timeout.vim
diff options
context:
space:
mode:
Diffstat (limited to 'autoload/insert_timeout.vim')
-rw-r--r--autoload/insert_timeout.vim27
1 files changed, 17 insertions, 10 deletions
diff --git a/autoload/insert_timeout.vim b/autoload/insert_timeout.vim
index 8ca3e7c..3dfe9ad 100644
--- a/autoload/insert_timeout.vim
+++ b/autoload/insert_timeout.vim
@@ -1,14 +1,21 @@
-" Set update time to configured variable or default 20 seconds
-function! insert_timeout#Enter() abort
+" Set update time to configured variable or default 20 seconds for duration of
+" insert
+function! insert_timeout#() abort
+
+ " Save current value of 'updatetime' into script variable
let s:updatetime = &updatetime
+
+ " Set 'updatetime' to configured variable or default
let &updatetime = get(g:, 'insert_timeout_duration', 20000)
-endfunction
-" Restore update time to its previous value
-function! insert_timeout#Leave() abort
- if !exists('s:updatetime')
- return
- endif
- let &updatetime = s:updatetime
- unlet s:updatetime
+ " Restore 'updatetime' when insert mode ends
+ autocmd insert_timeout InsertLeave *
+ \ let &updatetime = s:updatetime
+ \|autocmd! insert_timeout InsertLeave
+
+ " Stop the insert after 'updatetime' seconds
+ autocmd insert_timeout CursorHoldI *
+ \ stopinsert
+ \|autocmd! insert_timeout CursorHoldI
+
endfunction