Skip to content

Instantly share code, notes, and snippets.

@slimane
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slimane/9140355 to your computer and use it in GitHub Desktop.
Save slimane/9140355 to your computer and use it in GitHub Desktop.
" インサートモードに入るか、入力を行った最後の時間変数に保存
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