mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-29 00:06:29 +00:00
Update Vim plugin to take path argument
This commit is contained in:
parent
724724bd8c
commit
f28274109f
@ -140,8 +140,14 @@ Usage as Vim plugin
|
|||||||
If you install fzf as a Vim plugin, `:FZF` command will be added.
|
If you install fzf as a Vim plugin, `:FZF` command will be added.
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
|
" Look for files under current directory
|
||||||
:FZF
|
:FZF
|
||||||
:FZF --no-sort -m
|
|
||||||
|
" Look for files under your home directory
|
||||||
|
:FZF ~
|
||||||
|
|
||||||
|
" With options
|
||||||
|
:FZF --no-sort -m /tmp
|
||||||
```
|
```
|
||||||
|
|
||||||
You can override the source command which produces input to fzf.
|
You can override the source command which produces input to fzf.
|
||||||
|
@ -23,25 +23,37 @@
|
|||||||
|
|
||||||
let s:exec = expand('<sfile>:h:h').'/fzf'
|
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
|
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 tf = tempname()
|
||||||
let prefix = exists('g:fzf_source') ? g:fzf_source.'|' : ''
|
let prefix = exists('g:fzf_source') ? g:fzf_source.'|' : ''
|
||||||
let fzf = executable(s:exec) ? s:exec : 'fzf'
|
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
|
execute "silent !".prefix.fzf.' '.options." > ".tf
|
||||||
if !v:shell_error
|
if !v:shell_error
|
||||||
for line in readfile(tf)
|
for line in readfile(tf)
|
||||||
if !empty(line)
|
if !empty(line)
|
||||||
execute a:command.' '.line
|
execute a:command.' '.s:escape(line)
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
endif
|
endif
|
||||||
finally
|
finally
|
||||||
|
execute 'chdir '.s:escape(cwd)
|
||||||
redraw!
|
redraw!
|
||||||
silent! call delete(tf)
|
silent! call delete(tf)
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
command! -nargs=* FZF call fzf#run('silent e', <q-args>)
|
command! -nargs=* -complete=dir FZF call fzf#run('silent e', <f-args>)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user