diff --git a/README.md b/README.md index 05a4bbc..75a0626 100644 --- a/README.md +++ b/README.md @@ -110,16 +110,23 @@ through [README-VIM][README-VIM] to learn more about them. #### Preview window -If the width of the screen is wider than 120 columns, some commands will show -the preview window on the right. You can customize the behavior with -`g:fzf_preview_window`. Here are some examples: +Some commands will show the preview window on the right. You can customize the +behavior with `g:fzf_preview_window`. Here are some examples: ```vim -" Empty value to disable preview window altogether -let g:fzf_preview_window = '' +" This is the default option: +" - Preview window on the right with 50% width +" - CTRL-/ will toggle preview window. +" - Note that this array is passed as arguments to fzf#vim#with_preview function. +" - To learn more about preview window options, see `--preview-window` section of `man fzf`. +let g:fzf_preview_window = ['right:50%', 'ctrl-/'] -" Always enable preview window on the right with 60% width -let g:fzf_preview_window = 'right:60%' +" Preview window on the upper side of the window with 40% height, +" hidden by default, ctrl-/ to toggle +let g:fzf_preview_window = ['up:40%:hidden', 'ctrl-/'] + +" Empty value to disable preview window altogether +let g:fzf_preview_window = [] ``` ### Command-local options diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index 91cfa07..3a2d653 100644 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -155,7 +155,9 @@ function! fzf#vim#with_preview(...) else let preview_cmd = fzf#shellescape(s:bin.preview) endif - let preview += ['--preview', preview_cmd.' '.placeholder] + if len(placeholder) + let preview += ['--preview', preview_cmd.' '.placeholder] + end if len(args) call extend(preview, ['--bind', join(map(args, 'v:val.":toggle-preview"'), ',')]) diff --git a/doc/fzf-vim.txt b/doc/fzf-vim.txt index b32ae75..29807d8 100644 --- a/doc/fzf-vim.txt +++ b/doc/fzf-vim.txt @@ -1,4 +1,4 @@ -fzf-vim.txt fzf-vim Last change: August 12 2020 +fzf-vim.txt fzf-vim Last change: October 22 2020 FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-toc* ============================================================================== @@ -175,15 +175,22 @@ Preview window~ *g:fzf_preview_window* -If the width of the screen is wider than 120 columns, some commands will show -the preview window on the right. You can customize the behavior with -`g:fzf_preview_window`. Here are some examples: +Some commands will show the preview window on the right. You can customize the +behavior with `g:fzf_preview_window`. Here are some examples: > - " Empty value to disable preview window altogether - let g:fzf_preview_window = '' + " This is the default option: + " - Preview window on the right with 50% width + " - CTRL-/ will toggle preview window. + " - Note that this array is passed as arguments to fzf#vim#with_preview function. + " - To learn more about preview window options, see `--preview-window` section of `man fzf`. + let g:fzf_preview_window = ['right:50%', 'ctrl-/'] - " Always enable preview window on the right with 60% width - let g:fzf_preview_window = 'right:60%' + " Preview window on the upper side of the window with 40% height, + " hidden by default, ctrl-/ to toggle + let g:fzf_preview_window = ['up:40%:hidden', 'ctrl-/'] + + " Empty value to disable preview window altogether + let g:fzf_preview_window = [] < < Command-local options >_____________________________________________________~ diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 2565d40..55cb61c 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -39,27 +39,32 @@ function! s:defs(commands) endfor endfunction -function! s:p(bang, ...) - let preview_window = get(g:, 'fzf_preview_window', a:bang && &columns >= 80 || &columns >= 120 ? 'right': '') - if len(preview_window) - return call('fzf#vim#with_preview', add(copy(a:000), preview_window)) +function! s:p(...) + let preview_args = get(g:, 'fzf_preview_window', ['right', 'ctrl-/']) + if empty(preview_args) + return { 'options': ['--preview-window', 'hidden'] } endif - return {} + + " 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(, s:p(0), 0)', -\'command! -bang -nargs=? GitFiles call fzf#vim#gitfiles(, == "?" ? {} : s:p(0), 0)', -\'command! -bang -nargs=? GFiles call fzf#vim#gitfiles(, == "?" ? {} : s:p(0), 0)', -\'command! -bar -bang -nargs=? -complete=buffer Buffers call fzf#vim#buffers(, s:p(0, { "placeholder": "{1}" }), 0)', +\'command! -bang -nargs=? -complete=dir Files call fzf#vim#files(, s:p(), 0)', +\'command! -bang -nargs=? GitFiles call fzf#vim#gitfiles(, s:p( == "?" ? { "placeholder": "" } : {}), 0)', +\'command! -bang -nargs=? GFiles call fzf#vim#gitfiles(, s:p( == "?" ? { "placeholder": "" } : {}), 0)', +\'command! -bar -bang -nargs=? -complete=buffer Buffers call fzf#vim#buffers(, s:p({ "placeholder": "{1}" }), 0)', \'command! -bang -nargs=* Lines call fzf#vim#lines(, 0)', \'command! -bang -nargs=* BLines call fzf#vim#buffer_lines(, 0)', \'command! -bar -bang Colors call fzf#vim#colors(0)', -\'command! -bang -nargs=+ -complete=dir Locate call fzf#vim#locate(, s:p(0), 0)', -\'command! -bang -nargs=* Ag call fzf#vim#ag(, s:p(0), 0)', -\'command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case -- ".shellescape(), 1, s:p(0), 0)', +\'command! -bang -nargs=+ -complete=dir Locate call fzf#vim#locate(, s:p(), 0)', +\'command! -bang -nargs=* Ag call fzf#vim#ag(, s:p(), 0)', +\'command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case -- ".shellescape(), 1, s:p(), 0)', \'command! -bang -nargs=* Tags call fzf#vim#tags(, 0)', -\'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(, s:p(0, { "placeholder": "{2}:{3}" }), 0)', +\'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(, s:p({ "placeholder": "{2}:{3}" }), 0)', \'command! -bar -bang Snippets call fzf#vim#snippets(0)', \'command! -bar -bang Commands call fzf#vim#commands(0)', \'command! -bar -bang Marks call fzf#vim#marks(0)', @@ -69,7 +74,7 @@ call s:defs([ \'command! -bar -bang BCommits call fzf#vim#buffer_commits(0)', \'command! -bar -bang Maps call fzf#vim#maps("n", 0)', \'command! -bar -bang Filetypes call fzf#vim#filetypes(0)', -\'command! -bang -nargs=* History call s:history(, s:p(0), 0)']) +\'command! -bang -nargs=* History call s:history(, s:p(), 0)']) function! s:history(arg, extra, bang) let bang = a:bang || a:arg[len(a:arg)-1] == '!'