summaryrefslogtreecommitdiff
path: root/plugin/fzf.vim
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2014-06-27 21:03:25 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2014-06-27 21:03:25 +0900
commit3e91c189aea13472ee1f2757482507c24b9e1ff5 (patch)
tree7a1014bc2642f714f0b16d5cd74cbf64e6685f18 /plugin/fzf.vim
parentb0f80b686c0754d1fc1027a6122d57aab413a5be (diff)
downloadfzf-3e91c189aea13472ee1f2757482507c24b9e1ff5.tar.gz
[vim] Defer `type fzf` to reduce startup time
Diffstat (limited to 'plugin/fzf.vim')
-rw-r--r--plugin/fzf.vim32
1 files changed, 21 insertions, 11 deletions
diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index 919c3f0a..42c89fca 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -25,22 +25,27 @@ let s:min_tmux_width = 10
let s:min_tmux_height = 3
let s:default_tmux_height = '40%'
let s:launcher = 'xterm -e bash -ic %s'
+let s:fzf_rb = expand('<sfile>:h:h').'/fzf'
let s:cpo_save = &cpo
set cpo&vim
-call system('type fzf')
-if v:shell_error
- let s:fzf_rb = expand('<sfile>:h:h').'/fzf'
- if executable(s:fzf_rb)
- let s:exec = s:fzf_rb
+function! s:fzf_exec()
+ if !exists('s:exec')
+ call system('type fzf')
+ if v:shell_error
+ let s:exec = executable(s:fzf_rb) ? s:fzf_rb : ''
+ else
+ let s:exec = 'fzf'
+ endif
+ return s:fzf_exec()
+ elseif empty(s:exec)
+ unlet s:exec
+ throw 'fzf executable not found'
else
- echoerr 'fzf executable not found'
- finish
+ return s:exec
endif
-else
- let s:exec = 'fzf'
-endif
+endfunction
function! s:tmux_enabled()
if has('gui_running')
@@ -71,6 +76,11 @@ function! fzf#run(...) abort
let dict = exists('a:1') ? a:1 : {}
let temps = { 'result': tempname() }
let optstr = get(dict, 'options', '')
+ try
+ let fzf_exec = s:fzf_exec()
+ catch
+ throw v:exception
+ endtry
if has_key(dict, 'source')
let source = dict.source
@@ -87,7 +97,7 @@ function! fzf#run(...) abort
else
let prefix = ''
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)
return s:execute_tmux(dict, command, temps)