mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-06 12:44:24 +08:00
Make fzf#vim#preview process g:fzf_preview_window
Related #1023 Related #1225
This commit is contained in:
@@ -138,9 +138,19 @@ function! fzf#vim#with_preview(...)
|
||||
" Placeholder expression (TODO/TBD: undocumented)
|
||||
let placeholder = get(spec, 'placeholder', '{}')
|
||||
|
||||
" Preview window
|
||||
" g:fzf_preview_window
|
||||
if empty(args)
|
||||
let preview_args = get(g:, 'fzf_preview_window', ['right', 'ctrl-/'])
|
||||
if empty(preview_args)
|
||||
let args = ['hidden']
|
||||
else
|
||||
" For backward-compatiblity
|
||||
let args = type(preview_args) == type('') ? [preview_args] : copy(preview_args)
|
||||
endif
|
||||
endif
|
||||
|
||||
if len(args) && type(args[0]) == s:TYPE.string
|
||||
if args[0] !~# '^\(up\|down\|left\|right\)'
|
||||
if args[0] !~# '^\(up\|down\|left\|right\|hidden\)'
|
||||
throw 'invalid preview window: '.args[0]
|
||||
endif
|
||||
let window = args[0]
|
||||
|
||||
@@ -44,42 +44,29 @@ function! s:defs(commands)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:p(...)
|
||||
let preview_args = get(g:, 'fzf_preview_window', ['right', 'ctrl-/'])
|
||||
if empty(preview_args)
|
||||
return { 'options': ['--preview-window', 'hidden'] }
|
||||
endif
|
||||
|
||||
" For backward-compatiblity
|
||||
if type(preview_args) == type('')
|
||||
let preview_args = [preview_args]
|
||||
endif
|
||||
return call('fzf#vim#with_preview', extend(copy(a:000), preview_args))
|
||||
endfunction
|
||||
|
||||
call s:defs([
|
||||
\'command! -bang -nargs=? -complete=dir Files call fzf#vim#files(<q-args>, s:p(), <bang>0)',
|
||||
\'command! -bang -nargs=? GitFiles call fzf#vim#gitfiles(<q-args>, s:p(<q-args> == "?" ? { "placeholder": "" } : {}), <bang>0)',
|
||||
\'command! -bang -nargs=? GFiles call fzf#vim#gitfiles(<q-args>, s:p(<q-args> == "?" ? { "placeholder": "" } : {}), <bang>0)',
|
||||
\'command! -bar -bang -nargs=? -complete=buffer Buffers call fzf#vim#buffers(<q-args>, s:p({ "placeholder": "{1}" }), <bang>0)',
|
||||
\'command! -bang -nargs=? -complete=dir Files call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)',
|
||||
\'command! -bang -nargs=? GitFiles call fzf#vim#gitfiles(<q-args>, fzf#vim#with_preview(<q-args> == "?" ? { "placeholder": "" } : {}), <bang>0)',
|
||||
\'command! -bang -nargs=? GFiles call fzf#vim#gitfiles(<q-args>, fzf#vim#with_preview(<q-args> == "?" ? { "placeholder": "" } : {}), <bang>0)',
|
||||
\'command! -bar -bang -nargs=? -complete=buffer Buffers call fzf#vim#buffers(<q-args>, fzf#vim#with_preview({ "placeholder": "{1}" }), <bang>0)',
|
||||
\'command! -bang -nargs=* Lines call fzf#vim#lines(<q-args>, <bang>0)',
|
||||
\'command! -bang -nargs=* BLines call fzf#vim#buffer_lines(<q-args>, <bang>0)',
|
||||
\'command! -bar -bang Colors call fzf#vim#colors(<bang>0)',
|
||||
\'command! -bang -nargs=+ -complete=dir Locate call fzf#vim#locate(<q-args>, s:p(), <bang>0)',
|
||||
\'command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, s:p(), <bang>0)',
|
||||
\'command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case -- ".shellescape(<q-args>), 1, s:p(), <bang>0)',
|
||||
\'command! -bang -nargs=* Tags call fzf#vim#tags(<q-args>, s:p({ "placeholder": "--tag {2}:{-1}:{3}" }), <bang>0)',
|
||||
\'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(<q-args>, s:p({ "placeholder": "{2}:{3}" }), <bang>0)',
|
||||
\'command! -bang -nargs=+ -complete=dir Locate call fzf#vim#locate(<q-args>, fzf#vim#with_preview(), <bang>0)',
|
||||
\'command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, fzf#vim#with_preview(), <bang>0)',
|
||||
\'command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case -- ".shellescape(<q-args>), 1, fzf#vim#with_preview(), <bang>0)',
|
||||
\'command! -bang -nargs=* Tags call fzf#vim#tags(<q-args>, fzf#vim#with_preview({ "placeholder": "--tag {2}:{-1}:{3}" }), <bang>0)',
|
||||
\'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(<q-args>, fzf#vim#with_preview({ "placeholder": "{2}:{3}" }), <bang>0)',
|
||||
\'command! -bar -bang Snippets call fzf#vim#snippets(<bang>0)',
|
||||
\'command! -bar -bang Commands call fzf#vim#commands(<bang>0)',
|
||||
\'command! -bar -bang Marks call fzf#vim#marks(<bang>0)',
|
||||
\'command! -bar -bang Helptags call fzf#vim#helptags(<bang>0)',
|
||||
\'command! -bar -bang Windows call fzf#vim#windows(<bang>0)',
|
||||
\'command! -bar -bang Commits call fzf#vim#commits(s:p({ "placeholder": "" }), <bang>0)',
|
||||
\'command! -bar -bang BCommits call fzf#vim#buffer_commits(s:p({ "placeholder": "" }), <bang>0)',
|
||||
\'command! -bar -bang Commits call fzf#vim#commits(fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
|
||||
\'command! -bar -bang BCommits call fzf#vim#buffer_commits(fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
|
||||
\'command! -bar -bang Maps call fzf#vim#maps("n", <bang>0)',
|
||||
\'command! -bar -bang Filetypes call fzf#vim#filetypes(<bang>0)',
|
||||
\'command! -bang -nargs=* History call s:history(<q-args>, s:p(), <bang>0)'])
|
||||
\'command! -bang -nargs=* History call s:history(<q-args>, fzf#vim#with_preview(), <bang>0)'])
|
||||
|
||||
function! s:history(arg, extra, bang)
|
||||
let bang = a:bang || a:arg[len(a:arg)-1] == '!'
|
||||
|
||||
Reference in New Issue
Block a user