mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-08 21:44:48 +08:00
Add option to globally enable or disable preview window
This commit is contained in:
14
README.md
14
README.md
@@ -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
|
repository which supports a set of global option variables. So please read
|
||||||
through [README-VIM][README-VIM] to learn more about them.
|
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
|
### Command-local options
|
||||||
|
|
||||||
A few commands in fzf.vim can be customized with global option variables shown
|
A few commands in fzf.vim can be customized with global option variables shown
|
||||||
|
|||||||
@@ -88,6 +88,9 @@ function! fzf#vim#with_preview(...)
|
|||||||
call remove(args, 0)
|
call remove(args, 0)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" Placeholder expression (TODO/TBD: undocumented)
|
||||||
|
let placeholder = get(options, 'placeholder', '{}')
|
||||||
|
|
||||||
" Preview window
|
" Preview window
|
||||||
if len(args) && type(args[0]) == s:TYPE.string
|
if len(args) && type(args[0]) == s:TYPE.string
|
||||||
if args[0] !~# '^\(up\|down\|left\|right\)'
|
if args[0] !~# '^\(up\|down\|left\|right\)'
|
||||||
@@ -97,7 +100,7 @@ function! fzf#vim#with_preview(...)
|
|||||||
call remove(args, 0)
|
call remove(args, 0)
|
||||||
endif
|
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)
|
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"'), ',')])
|
||||||
@@ -616,13 +619,15 @@ endfunction
|
|||||||
|
|
||||||
function! s:format_buffer(b)
|
function! s:format_buffer(b)
|
||||||
let name = bufname(a:b)
|
let name = bufname(a:b)
|
||||||
|
let line = getbufinfo(a:b)[0]['lnum']
|
||||||
let name = empty(name) ? '[No Name]' : fnamemodify(name, ":p:~:.")
|
let name = empty(name) ? '[No Name]' : fnamemodify(name, ":p:~:.")
|
||||||
let flag = a:b == bufnr('') ? s:blue('%', 'Conditional') :
|
let flag = a:b == bufnr('') ? s:blue('%', 'Conditional') :
|
||||||
\ (a:b == bufnr('#') ? s:magenta('#', 'Special') : ' ')
|
\ (a:b == bufnr('#') ? s:magenta('#', 'Special') : ' ')
|
||||||
let modified = getbufvar(a:b, '&modified') ? s:red(' [+]', 'Exception') : ''
|
let modified = getbufvar(a:b, '&modified') ? s:red(' [+]', 'Exception') : ''
|
||||||
let readonly = getbufvar(a:b, '&modifiable') ? '' : s:green(' [RO]', 'Constant')
|
let readonly = getbufvar(a:b, '&modifiable') ? '' : s:green(' [RO]', 'Constant')
|
||||||
let extra = join(filter([modified, readonly], '!empty(v:val)'), '')
|
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
|
endfunction
|
||||||
|
|
||||||
function! s:sort_buffers(...)
|
function! s:sort_buffers(...)
|
||||||
@@ -641,7 +646,7 @@ function! fzf#vim#buffers(...)
|
|||||||
return s:fzf('buffers', {
|
return s:fzf('buffers', {
|
||||||
\ 'source': map(s:buflisted_sorted(), 's:format_buffer(v:val)'),
|
\ 'source': map(s:buflisted_sorted(), 's:format_buffer(v:val)'),
|
||||||
\ 'sink*': s:function('s:bufopen'),
|
\ '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)
|
\}, args)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
@@ -17,14 +17,19 @@ if [[ $1 =~ ^[A-Z]:\\ ]]; then
|
|||||||
CENTER=${INPUT[2]}
|
CENTER=${INPUT[2]}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ ! "$CENTER" =~ ^[0-9]*$ ]]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
FILE="${FILE/#\~\//$HOME/}"
|
FILE="${FILE/#\~\//$HOME/}"
|
||||||
if [ ! -r "$FILE" ]; then
|
if [ ! -r "$FILE" ]; then
|
||||||
echo "File not found ${FILE}"
|
echo "File not found ${FILE}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$(file --dereference --mime "$FILE")" =~ binary ]]; then
|
MIME=$(file --dereference --mime "$FILE")
|
||||||
echo "$1 is a binary file"
|
if [[ "$MIME" =~ binary ]]; then
|
||||||
|
echo "$MIME"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -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*
|
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
|
Commands
|
||||||
Customization
|
Customization
|
||||||
Global options
|
Global options
|
||||||
|
Preview window
|
||||||
Command-local options
|
Command-local options
|
||||||
Advanced customization
|
Advanced customization
|
||||||
Vim functions
|
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
|
{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 >_____________________________________________________~
|
< Command-local options >_____________________________________________________~
|
||||||
*fzf-vim-command-local-options*
|
*fzf-vim-command-local-options*
|
||||||
|
|
||||||
|
|||||||
@@ -39,17 +39,25 @@ function! s:defs(commands)
|
|||||||
endfor
|
endfor
|
||||||
endfunction
|
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([
|
call s:defs([
|
||||||
\'command! -bang -nargs=? -complete=dir Files call fzf#vim#files(<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>, <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>, <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>, <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=* 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>, <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>, <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, <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=* Tags call fzf#vim#tags(<q-args>, <bang>0)',
|
||||||
\'command! -bang -nargs=* BTags call fzf#vim#buffer_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)',
|
\'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 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>, <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] == '!'
|
let bang = a:bang || a:arg[len(a:arg)-1] == '!'
|
||||||
if a:arg[0] == ':'
|
if a:arg[0] == ':'
|
||||||
call fzf#vim#command_history(bang)
|
call fzf#vim#command_history(bang)
|
||||||
elseif a:arg[0] == '/'
|
elseif a:arg[0] == '/'
|
||||||
call fzf#vim#search_history(bang)
|
call fzf#vim#search_history(bang)
|
||||||
else
|
|
||||||
call fzf#vim#history(bang)
|
|
||||||
endif
|
endif
|
||||||
|
call fzf#vim#history(a:extra, bang)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fzf#complete(...)
|
function! fzf#complete(...)
|
||||||
|
|||||||
Reference in New Issue
Block a user