diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index f9a5eef..4d069a9 100644 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -1252,12 +1252,13 @@ function! fzf#vim#complete(...) let s:opts = s:eval(s:opts, 'options', s:query) let s:opts = s:eval(s:opts, 'extra_options', s:query) if has_key(s:opts, 'extra_options') - let s:opts.options = - \ join(filter([get(s:opts, 'options', ''), remove(s:opts, 'extra_options')], '!empty(v:val)')) + call s:merge_opts(s:opts, remove(s:opts, 'extra_options')) endif if has_key(s:opts, 'options') " FIXME: fzf currently doesn't have --no-expect option - let s:opts.options = substitute(s:opts.options, '--expect=[^ ]*', '', 'g') + if type(s:opts.options) == s:TYPE.string + let s:opts.options = substitute(s:opts.options, '--expect=[^ ]*', '', 'g') + endif endif call feedkeys("\(-fzf-complete-trigger)") diff --git a/autoload/fzf/vim/complete.vim b/autoload/fzf/vim/complete.vim index 2a0c2b6..03c9b3b 100644 --- a/autoload/fzf/vim/complete.vim +++ b/autoload/fzf/vim/complete.vim @@ -23,6 +23,7 @@ let s:cpo_save = &cpo set cpo&vim +let s:is_win = has('win32') || has('win64') function! s:extend(base, extra) let base = copy(a:base) @@ -58,25 +59,26 @@ endfunction " ---------------------------------------------------------------------------- function! s:file_split_prefix(prefix) let expanded = expand(a:prefix) + let slash = (s:is_win && !&shellslash) ? '\\' : '/' return isdirectory(expanded) ? \ [expanded, - \ substitute(a:prefix, '/*$', '/', ''), + \ substitute(a:prefix, '[/\\]*$', slash, ''), \ ''] : \ [fnamemodify(expanded, ':h'), - \ substitute(fnamemodify(a:prefix, ':h'), '/*$', '/', ''), + \ substitute(fnamemodify(a:prefix, ':h'), '[/\\]*$', slash, ''), \ fnamemodify(expanded, ':t')] endfunction function! s:file_source(prefix) let [dir, head, tail] = s:file_split_prefix(a:prefix) return printf( - \ "cd %s && ".s:file_cmd." | sed 's:^:%s:'", - \ shellescape(dir), empty(a:prefix) || a:prefix == tail ? '' : head) + \ "cd %s && ".s:file_cmd." | sed %s", + \ fzf#shellescape(dir), fzf#shellescape('s:^:'.(empty(a:prefix) || a:prefix == tail ? '' : head).':')) endfunction function! s:file_options(prefix) let [_, head, tail] = s:file_split_prefix(a:prefix) - return printf('--prompt %s --query %s', shellescape(head), shellescape(tail)) + return ['--prompt', head, '--query', tail] endfunction function! s:fname_prefix(str) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index a1281bc..79e3d9d 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -23,6 +23,7 @@ let s:cpo_save = &cpo set cpo&vim +let s:is_win = has('win32') || has('win64') function! s:defs(commands) let prefix = get(g:, 'fzf_command_prefix', '') @@ -123,9 +124,14 @@ augroup fzf_buffers augroup END inoremap (fzf-complete-word) fzf#vim#complete#word() -inoremap (fzf-complete-path) fzf#vim#complete#path("find . -path '*/\.*' -prune -o -print \| sed '1d;s:^..::'") -inoremap (fzf-complete-file) fzf#vim#complete#path("find . -path '*/\.*' -prune -o -type f -print -o -type l -print \| sed 's:^..::'") -inoremap (fzf-complete-file-ag) fzf#vim#complete#path("ag -l -g ''") +if s:is_win + inoremap (fzf-complete-path) fzf#vim#complete#path('dir /s/b') + inoremap (fzf-complete-file) fzf#vim#complete#path('dir /s/b/a:-d') +else + inoremap (fzf-complete-path) fzf#vim#complete#path("find . -path '*/\.*' -prune -o -print \| sed '1d;s:^..::'") + inoremap (fzf-complete-file) fzf#vim#complete#path("find . -path '*/\.*' -prune -o -type f -print -o -type l -print \| sed 's:^..::'") +endif +inoremap (fzf-complete-file-ag) fzf#vim#complete#path('ag -l -g ""') inoremap (fzf-complete-line) fzf#vim#complete#line() inoremap (fzf-complete-buffer-line) fzf#vim#complete#buffer_line()