Last active
August 29, 2015 13:56
-
-
Save slimane/9140355 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" インサートモードに入るか、入力を行った最後の時間変数に保存 | |
autocmd! InsertEnter,InsertChange * :let s:last_action_time = localtime() | |
autocmd! CursorMovedI * :call s:leave_insert_mode() | let s:last_action_time = localtime() | |
autocmd! InsertCharPre * :call s:leave_insert_mode("call feedkeys('" . v:char . "', 'n')", "let v:char = '' ") | |
" 最後の入力からこの秒数を超えた時間が経過していればInsertを終了する | |
let s:wait_sec = 5 | |
function! s:leave_insert_mode(...) | |
let s:last_action_time = get(s:, "last_action_time", localtime()) | |
let l:elapsed_sec = localtime() - s:last_action_time | |
" 経過時間が指定待ち時間を超えていれば | |
if l:elapsed_sec > s:wait_sec | |
call feedkeys("\<ESC>") | |
" 文字列として指定されたlambda式を実行 | |
for action in a:000 | |
execute action | |
endfor | |
endif | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment