Update g:fzf_preview_window to be a list with optional toggle keys

- The default preview window option will be ['right', 'ctrl-/']
  regardless of screen width or <bang>
- This will also fix #1010
This commit is contained in:
Junegunn Choi
2020-10-22 16:58:43 +09:00
parent 0eb385065b
commit 44057cce0e
4 changed files with 51 additions and 30 deletions

View File

@@ -110,16 +110,23 @@ through [README-VIM][README-VIM] to learn more about them.
#### Preview window #### Preview window
If the width of the screen is wider than 120 columns, some commands will show Some commands will show the preview window on the right. You can customize the
the preview window on the right. You can customize the behavior with behavior with `g:fzf_preview_window`. Here are some examples:
`g:fzf_preview_window`. Here are some examples:
```vim ```vim
" Empty value to disable preview window altogether " This is the default option:
let g:fzf_preview_window = '' " - 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 " Preview window on the upper side of the window with 40% height,
let g:fzf_preview_window = 'right:60%' " 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 ### Command-local options

View File

@@ -155,7 +155,9 @@ function! fzf#vim#with_preview(...)
else else
let preview_cmd = fzf#shellescape(s:bin.preview) let preview_cmd = fzf#shellescape(s:bin.preview)
endif endif
let preview += ['--preview', preview_cmd.' '.placeholder] if len(placeholder)
let preview += ['--preview', preview_cmd.' '.placeholder]
end
if len(args) if len(args)
call extend(preview, ['--bind', join(map(args, 'v:val.":toggle-preview"'), ',')]) call extend(preview, ['--bind', join(map(args, 'v:val.":toggle-preview"'), ',')])

View File

@@ -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* FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-toc*
============================================================================== ==============================================================================
@@ -175,15 +175,22 @@ Preview window~
*g:fzf_preview_window* *g:fzf_preview_window*
If the width of the screen is wider than 120 columns, some commands will show Some commands will show the preview window on the right. You can customize the
the preview window on the right. You can customize the behavior with behavior with `g:fzf_preview_window`. Here are some examples:
`g:fzf_preview_window`. Here are some examples:
> >
" Empty value to disable preview window altogether " This is the default option:
let g:fzf_preview_window = '' " - 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 " Preview window on the upper side of the window with 40% height,
let g:fzf_preview_window = 'right:60%' " 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 >_____________________________________________________~ < Command-local options >_____________________________________________________~

View File

@@ -39,27 +39,32 @@ function! s:defs(commands)
endfor endfor
endfunction endfunction
function! s:p(bang, ...) function! s:p(...)
let preview_window = get(g:, 'fzf_preview_window', a:bang && &columns >= 80 || &columns >= 120 ? 'right': '') let preview_args = get(g:, 'fzf_preview_window', ['right', 'ctrl-/'])
if len(preview_window) if empty(preview_args)
return call('fzf#vim#with_preview', add(copy(a:000), preview_window)) return { 'options': ['--preview-window', 'hidden'] }
endif 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 endfunction
call s:defs([ call s:defs([
\'command! -bang -nargs=? -complete=dir Files call fzf#vim#files(<q-args>, s:p(<bang>0), <bang>0)', \'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>, <q-args> == "?" ? {} : s:p(<bang>0), <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>, <q-args> == "?" ? {} : s:p(<bang>0), <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(<bang>0, { "placeholder": "{1}" }), <bang>0)', \'command! -bar -bang -nargs=? -complete=buffer Buffers call fzf#vim#buffers(<q-args>, s:p({ "placeholder": "{1}" }), <bang>0)',
\'command! -bang -nargs=* Lines call fzf#vim#lines(<q-args>, <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! -bang -nargs=* BLines call fzf#vim#buffer_lines(<q-args>, <bang>0)',
\'command! -bar -bang Colors call fzf#vim#colors(<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), <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), <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), <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>, <bang>0)', \'command! -bang -nargs=* Tags call fzf#vim#tags(<q-args>, <bang>0)',
\'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(<q-args>, s:p(<bang>0, { "placeholder": "{2}:{3}" }), <bang>0)', \'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(<q-args>, s:p({ "placeholder": "{2}:{3}" }), <bang>0)',
\'command! -bar -bang Snippets call fzf#vim#snippets(<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 Commands call fzf#vim#commands(<bang>0)',
\'command! -bar -bang Marks call fzf#vim#marks(<bang>0)', \'command! -bar -bang Marks call fzf#vim#marks(<bang>0)',
@@ -69,7 +74,7 @@ call s:defs([
\'command! -bar -bang BCommits call fzf#vim#buffer_commits(<bang>0)', \'command! -bar -bang BCommits call fzf#vim#buffer_commits(<bang>0)',
\'command! -bar -bang Maps call fzf#vim#maps("n", <bang>0)', \'command! -bar -bang Maps call fzf#vim#maps("n", <bang>0)',
\'command! -bar -bang Filetypes call fzf#vim#filetypes(<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), <bang>0)']) \'command! -bang -nargs=* History call s:history(<q-args>, s:p(), <bang>0)'])
function! s:history(arg, extra, bang) function! s:history(arg, extra, bang)
let bang = a:bang || a:arg[len(a:arg)-1] == '!' let bang = a:bang || a:arg[len(a:arg)-1] == '!'