Add option to globally enable or disable preview window

This commit is contained in:
Junegunn Choi
2020-03-15 16:13:51 +09:00
parent ed9d66c2a6
commit 15ed47f561
5 changed files with 65 additions and 17 deletions

View File

@@ -105,6 +105,20 @@ Every command in fzf.vim internally calls `fzf#wrap` function of the main
repository which supports a set of global option variables. So please read
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:
```vim
" Empty value to disable preview window altogether
let g:fzf_preview_window = ''
" Always enable preview window on the right with 60% width
let g:fzf_preview_window = 'right:60%'
```
### Command-local options
A few commands in fzf.vim can be customized with global option variables shown

View File

@@ -88,6 +88,9 @@ function! fzf#vim#with_preview(...)
call remove(args, 0)
endif
" Placeholder expression (TODO/TBD: undocumented)
let placeholder = get(options, 'placeholder', '{}')
" Preview window
if len(args) && type(args[0]) == s:TYPE.string
if args[0] !~# '^\(up\|down\|left\|right\)'
@@ -97,7 +100,7 @@ function! fzf#vim#with_preview(...)
call remove(args, 0)
endif
let preview = ['--preview-window', window, '--preview', (s:is_win ? s:bin.preview : fzf#shellescape(s:bin.preview)).' {}']
let preview = ['--preview-window', window, '--preview', (s:is_win ? s:bin.preview : fzf#shellescape(s:bin.preview)).' '.placeholder]
if len(args)
call extend(preview, ['--bind', join(map(args, 'v:val.":toggle-preview"'), ',')])
@@ -616,13 +619,15 @@ endfunction
function! s:format_buffer(b)
let name = bufname(a:b)
let line = getbufinfo(a:b)[0]['lnum']
let name = empty(name) ? '[No Name]' : fnamemodify(name, ":p:~:.")
let flag = a:b == bufnr('') ? s:blue('%', 'Conditional') :
\ (a:b == bufnr('#') ? s:magenta('#', 'Special') : ' ')
let modified = getbufvar(a:b, '&modified') ? s:red(' [+]', 'Exception') : ''
let readonly = getbufvar(a:b, '&modifiable') ? '' : s:green(' [RO]', 'Constant')
let extra = join(filter([modified, readonly], '!empty(v:val)'), '')
return s:strip(printf("[%s] %s\t%s\t%s", s:yellow(a:b, 'Number'), flag, name, extra))
let target = line == 0 ? name : name.':'.line
return s:strip(printf("%s\t[%s] %s\t%s\t%s", target, s:yellow(a:b, 'Number'), flag, name, extra))
endfunction
function! s:sort_buffers(...)
@@ -641,7 +646,7 @@ function! fzf#vim#buffers(...)
return s:fzf('buffers', {
\ 'source': map(s:buflisted_sorted(), 's:format_buffer(v:val)'),
\ 'sink*': s:function('s:bufopen'),
\ 'options': ['+m', '-x', '--tiebreak=index', '--header-lines=1', '--ansi', '-d', '\t', '-n', '2,1..2', '--prompt', 'Buf> ', '--query', query]
\ 'options': ['+m', '-x', '--tiebreak=index', '--header-lines=1', '--ansi', '-d', '\t', '--with-nth', '2..', '-n', '2,1..2', '--prompt', 'Buf> ', '--query', query]
\}, args)
endfunction

View File

@@ -17,14 +17,19 @@ if [[ $1 =~ ^[A-Z]:\\ ]]; then
CENTER=${INPUT[2]}
fi
if [[ ! "$CENTER" =~ ^[0-9]*$ ]]; then
exit 1
fi
FILE="${FILE/#\~\//$HOME/}"
if [ ! -r "$FILE" ]; then
echo "File not found ${FILE}"
exit 1
fi
if [[ "$(file --dereference --mime "$FILE")" =~ binary ]]; then
echo "$1 is a binary file"
MIME=$(file --dereference --mime "$FILE")
if [[ "$MIME" =~ binary ]]; then
echo "$MIME"
exit 0
fi

View File

@@ -1,4 +1,4 @@
fzf-vim.txt fzf-vim Last change: February 5 2020
fzf-vim.txt fzf-vim Last change: March 15 2020
FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-toc*
==============================================================================
@@ -10,6 +10,7 @@ FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-to
Commands
Customization
Global options
Preview window
Command-local options
Advanced customization
Vim functions
@@ -160,6 +161,22 @@ through {README-VIM}{4} to learn more about them.
{4} https://github.com/junegunn/fzf/blob/master/README-VIM.md
Preview window~
*fzf-vim-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:
>
" Empty value to disable preview window altogether
let g:fzf_preview_window = ''
" Always enable preview window on the right with 60% width
let g:fzf_preview_window = 'right:60%'
<
< Command-local options >_____________________________________________________~
*fzf-vim-command-local-options*

View File

@@ -39,17 +39,25 @@ 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))
endif
return {}
endfunction
call s:defs([
\'command! -bang -nargs=? -complete=dir Files call fzf#vim#files(<q-args>, <bang>0)',
\'command! -bang -nargs=? GitFiles call fzf#vim#gitfiles(<q-args>, <bang>0)',
\'command! -bang -nargs=? GFiles call fzf#vim#gitfiles(<q-args>, <bang>0)',
\'command! -bar -bang -nargs=? -complete=buffer Buffers call fzf#vim#buffers(<q-args>, <bang>0)',
\'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}", "options": ["-d", "\t"] }), <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>, <bang>0)',
\'command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, <bang>0)',
\'command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case ".shellescape(<q-args>), 1, <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=* Tags call fzf#vim#tags(<q-args>, <bang>0)',
\'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(<q-args>, <bang>0)',
\'command! -bar -bang Snippets call fzf#vim#snippets(<bang>0)',
@@ -61,17 +69,16 @@ 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>, <bang>0)'])
\'command! -bang -nargs=* History call s:history(<q-args>, s:p(<bang>0), <bang>0)'])
function! s:history(arg, bang)
function! s:history(arg, extra, bang)
let bang = a:bang || a:arg[len(a:arg)-1] == '!'
if a:arg[0] == ':'
call fzf#vim#command_history(bang)
elseif a:arg[0] == '/'
call fzf#vim#search_history(bang)
else
call fzf#vim#history(bang)
endif
call fzf#vim#history(a:extra, bang)
endfunction
function! fzf#complete(...)