diff --git a/README.md b/README.md index cf45bac..3413242 100644 --- a/README.md +++ b/README.md @@ -139,13 +139,25 @@ If you install fzf as a Vim plugin, `:FZF` command will be added. ```vim :FZF -:FZF --no-sort +:FZF --no-sort -m ``` -You can override the command which produces input to fzf. +You can override the source command which produces input to fzf. ```vim -let g:fzf_command = 'find . -type f' +let g:fzf_source = 'find . -type f' +``` + +And you can predefine default options to fzf command. + +```vim +let g:fzf_options = '--no-color --extended' +``` + +For more advanced uses, you can call `fzf#run` function as follows. + +```vim +:call fzf#run('tabedit', '-m +c') ``` Most of the time, you will prefer native Vim plugins with better integration diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 7066403..206f571 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -23,23 +23,25 @@ let s:exec = expand(':h:h').'/fzf' -function! s:fzf(args) +function! fzf#run(command, args) try - let tf = tempname() - let prefix = exists('g:fzf_command') ? g:fzf_command.'|' : '' - let fzf = executable(s:exec) ? s:exec : 'fzf' - execute "silent !".prefix.fzf." ".a:args." > ".tf + 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 + execute "silent !".prefix.fzf.' '.options." > ".tf if !v:shell_error - let file = join(readfile(tf), '') - if !empty(file) - execute 'silent e '.file - endif + for line in readfile(tf) + if !empty(line) + execute a:command.' '.line + endif + endfor endif finally - silent! call delete(tf) redraw! + silent! call delete(tf) endtry endfunction -command! -nargs=* FZF call s:fzf() +command! -nargs=* FZF call fzf#run('silent e', )