summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2013-11-20 10:31:33 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2013-11-20 10:31:33 +0900
commitf28274109f13092ccd0df2be5da54a39936fadb4 (patch)
tree2b4f738b44101c91932c59852e7924cc6bc6c091 /plugin
parent724724bd8cc048c4c3a7a77687ec4562abea979f (diff)
downloadfzf-f28274109f13092ccd0df2be5da54a39936fadb4.tar.gz
Update Vim plugin to take path argument
Diffstat (limited to 'plugin')
-rw-r--r--plugin/fzf.vim20
1 files changed, 16 insertions, 4 deletions
diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index 206f571d..69ca19b9 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -23,25 +23,37 @@
let s:exec = expand('<sfile>:h:h').'/fzf'
-function! fzf#run(command, args)
+function! s:escape(path)
+ return substitute(a:path, ' ', '\\ ', 'g')
+endfunction
+
+function! fzf#run(command, ...)
+ let cwd = getcwd()
try
+ let args = copy(a:000)
+ if len(args) > 0
+ let dir = remove(args, -1)
+ execute 'chdir '.s:escape(dir)
+ endif
+ let argstr = join(args)
let tf = tempname()
let prefix = exists('g:fzf_source') ? g:fzf_source.'|' : ''
let fzf = executable(s:exec) ? s:exec : 'fzf'
- let options = empty(a:args) ? get(g:, 'fzf_options', '') : a:args
+ let options = empty(argstr) ? get(g:, 'fzf_options', '') : argstr
execute "silent !".prefix.fzf.' '.options." > ".tf
if !v:shell_error
for line in readfile(tf)
if !empty(line)
- execute a:command.' '.line
+ execute a:command.' '.s:escape(line)
endif
endfor
endif
finally
+ execute 'chdir '.s:escape(cwd)
redraw!
silent! call delete(tf)
endtry
endfunction
-command! -nargs=* FZF call fzf#run('silent e', <q-args>)
+command! -nargs=* -complete=dir FZF call fzf#run('silent e', <f-args>)