Skip to content

Commit

Permalink
Update g:fzf_preview_window to be a list with optional toggle keys
Browse files Browse the repository at this point in the history
- The default preview window option will be ['right', 'ctrl-/']
  regardless of screen width or <bang>
- This will also fix #1010
  • Loading branch information
junegunn committed Oct 22, 2020
1 parent 0eb3850 commit 44057cc
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 30 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-/']
" 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-/']
" Always enable preview window on the right with 60% width
let g:fzf_preview_window = 'right:60%'
" Empty value to disable preview window altogether
let g:fzf_preview_window = []
```

### Command-local options
Expand Down
4 changes: 3 additions & 1 deletion autoload/fzf/vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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"'), ',')])
Expand Down
23 changes: 15 additions & 8 deletions doc/fzf-vim.txt
Original file line number Diff line number Diff line change
@@ -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*
==============================================================================

Expand Down Expand Up @@ -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-/']
" 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-/']
" Always enable preview window on the right with 60% width
let g:fzf_preview_window = 'right:60%'
" Empty value to disable preview window altogether
let g:fzf_preview_window = []
<

< Command-local options >_____________________________________________________~
Expand Down
33 changes: 19 additions & 14 deletions plugin/fzf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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(<q-args>, s:p(<bang>0), <bang>0)',
\'command! -bang -nargs=? GitFiles call fzf#vim#gitfiles(<q-args>, <q-args> == "?" ? {} : s:p(<bang>0), <bang>0)',
\'command! -bang -nargs=? GFiles call fzf#vim#gitfiles(<q-args>, <q-args> == "?" ? {} : s:p(<bang>0), <bang>0)',
\'command! -bar -bang -nargs=? -complete=buffer Buffers call fzf#vim#buffers(<q-args>, s:p(<bang>0, { "placeholder": "{1}" }), <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>, 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=* 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), <bang>0)',
\'command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, 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), <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>, <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 Commands call fzf#vim#commands(<bang>0)',
\'command! -bar -bang Marks call fzf#vim#marks(<bang>0)',
Expand All @@ -69,7 74,7 @@ call s:defs([
\'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 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)
let bang = a:bang || a:arg[len(a:arg)-1] == '!'
Expand Down

0 comments on commit 44057cc

Please sign in to comment.