Dotfiles/site-modules/core/files/vim/plugin/defer.vim
Ade Attwood 80239af169 refactor(core): start to make dotfiles public
This is the first commit that brings the privet dotfiles to a public
reop previously this was all one puppet module. Now this has been split
out so I can put all of the private files in a private puppet module
2020-09-20 06:22:17 +01:00

40 lines
1.2 KiB
VimL

"
" Defer command for starting work after vim has loaded
"
" This is biased from Greg Hurrell's Profiling and optimization screen cast in
" his implementation he is using the `CursorHold,CursorHoldI` auto command
" that didn't really work for me. This uses `timer_start` to set a timer when
" to start the work. This is then started on `VimEnter` when everything has
" loaded. There are two levels of defer one at `250ms` and `500ms` This is for
" calling functions that depend on something that has already been deferred.
"
" You can use this by adding a function to the user auto command `WincentSoftDefer`
"
" autocmd User WincentSoftDefer call s:do_work()
"
function HardDefer(timer)
augroup WincentIdleboot
autocmd!
augroup END
doautocmd User WincentHardDefer
autocmd! User WincentHardDefer
endfunction
function SoftDefer(timer)
augroup WincentIdleboot
autocmd!
augroup END
doautocmd User WincentSoftDefer
autocmd! User WincentSoftDefer
endfunction
augroup WincentIdleboot
autocmd!
if has('vim_starting')
autocmd VimEnter * call timer_start(250, 'SoftDefer')
autocmd VimEnter * call timer_start(500, 'HardDefer')
endif
augroup END