[vim] Defer type fzf
to reduce startup time
This commit is contained in:
parent
b0f80b686c
commit
3e91c189ae
@ -25,22 +25,27 @@ let s:min_tmux_width = 10
|
|||||||
let s:min_tmux_height = 3
|
let s:min_tmux_height = 3
|
||||||
let s:default_tmux_height = '40%'
|
let s:default_tmux_height = '40%'
|
||||||
let s:launcher = 'xterm -e bash -ic %s'
|
let s:launcher = 'xterm -e bash -ic %s'
|
||||||
|
let s:fzf_rb = expand('<sfile>:h:h').'/fzf'
|
||||||
|
|
||||||
let s:cpo_save = &cpo
|
let s:cpo_save = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
|
|
||||||
|
function! s:fzf_exec()
|
||||||
|
if !exists('s:exec')
|
||||||
call system('type fzf')
|
call system('type fzf')
|
||||||
if v:shell_error
|
if v:shell_error
|
||||||
let s:fzf_rb = expand('<sfile>:h:h').'/fzf'
|
let s:exec = executable(s:fzf_rb) ? s:fzf_rb : ''
|
||||||
if executable(s:fzf_rb)
|
|
||||||
let s:exec = s:fzf_rb
|
|
||||||
else
|
|
||||||
echoerr 'fzf executable not found'
|
|
||||||
finish
|
|
||||||
endif
|
|
||||||
else
|
else
|
||||||
let s:exec = 'fzf'
|
let s:exec = 'fzf'
|
||||||
endif
|
endif
|
||||||
|
return s:fzf_exec()
|
||||||
|
elseif empty(s:exec)
|
||||||
|
unlet s:exec
|
||||||
|
throw 'fzf executable not found'
|
||||||
|
else
|
||||||
|
return s:exec
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:tmux_enabled()
|
function! s:tmux_enabled()
|
||||||
if has('gui_running')
|
if has('gui_running')
|
||||||
@ -71,6 +76,11 @@ function! fzf#run(...) abort
|
|||||||
let dict = exists('a:1') ? a:1 : {}
|
let dict = exists('a:1') ? a:1 : {}
|
||||||
let temps = { 'result': tempname() }
|
let temps = { 'result': tempname() }
|
||||||
let optstr = get(dict, 'options', '')
|
let optstr = get(dict, 'options', '')
|
||||||
|
try
|
||||||
|
let fzf_exec = s:fzf_exec()
|
||||||
|
catch
|
||||||
|
throw v:exception
|
||||||
|
endtry
|
||||||
|
|
||||||
if has_key(dict, 'source')
|
if has_key(dict, 'source')
|
||||||
let source = dict.source
|
let source = dict.source
|
||||||
@ -87,7 +97,7 @@ function! fzf#run(...) abort
|
|||||||
else
|
else
|
||||||
let prefix = ''
|
let prefix = ''
|
||||||
endif
|
endif
|
||||||
let command = prefix.s:exec.' '.optstr.' > '.temps.result
|
let command = prefix.fzf_exec.' '.optstr.' > '.temps.result
|
||||||
|
|
||||||
if s:tmux_enabled() && s:tmux_splittable(dict)
|
if s:tmux_enabled() && s:tmux_splittable(dict)
|
||||||
return s:execute_tmux(dict, command, temps)
|
return s:execute_tmux(dict, command, temps)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user