Use native preview scroll of fzf 0.22.0

This allows you to scroll upwards

Fix #1053
Fix #751
Fix #749
This commit is contained in:
Junegunn Choi
2020-07-30 12:51:06 +09:00
parent 23dda8602f
commit 4145f53f3d
5 changed files with 14 additions and 24 deletions

View File

@@ -50,6 +50,7 @@ so you can omit it if you use a plugin manager that doesn't support hooks.
### Dependencies ### Dependencies
- [fzf][fzf-main] 0.22.0 or above
- For syntax-highlighted preview, install [bat](https://github.com/sharkdp/bat) - For syntax-highlighted preview, install [bat](https://github.com/sharkdp/bat)
- `Ag` requires [The Silver Searcher (ag)][ag] - `Ag` requires [The Silver Searcher (ag)][ag]
- `Rg` requires [ripgrep (rg)][rg] - `Rg` requires [ripgrep (rg)][rg]

View File

@@ -584,7 +584,7 @@ function! fzf#vim#gitfiles(args, ...)
let wrapped = fzf#wrap({ let wrapped = fzf#wrap({
\ 'source': 'git -c color.status=always status --short --untracked-files=all', \ 'source': 'git -c color.status=always status --short --untracked-files=all',
\ 'dir': root, \ 'dir': root,
\ 'options': ['--ansi', '--multi', '--nth', '2..,..', '--tiebreak=index', '--prompt', 'GitFiles?> ', '--preview', 'sh -c "(git diff --color=always -- {-1} | sed 1,4d; cat {-1}) | head -500"'] \ 'options': ['--ansi', '--multi', '--nth', '2..,..', '--tiebreak=index', '--prompt', 'GitFiles?> ', '--preview', 'sh -c "(git diff --color=always -- {-1} | sed 1,4d; cat {-1}) | head -1000"']
\}) \})
call s:remove_layout(wrapped) call s:remove_layout(wrapped)
let wrapped.common_sink = remove(wrapped, 'sink*') let wrapped.common_sink = remove(wrapped, 'sink*')
@@ -648,7 +648,7 @@ function! fzf#vim#_format_buffer(b)
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)'), '')
let target = line == 0 ? name : name.':'.line 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)) return s:strip(printf("%s\t%d\t[%s] %s\t%s\t%s", target, line, s:yellow(a:b, 'Number'), flag, name, extra))
endfunction endfunction
function! s:sort_buffers(...) function! s:sort_buffers(...)
@@ -667,7 +667,7 @@ function! fzf#vim#buffers(...)
return s:fzf('buffers', { return s:fzf('buffers', {
\ 'source': map(fzf#vim#_buflisted_sorted(), 'fzf#vim#_format_buffer(v:val)'), \ 'source': map(fzf#vim#_buflisted_sorted(), 'fzf#vim#_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', '--with-nth', '2..', '-n', '2,1..2', '--prompt', 'Buf> ', '--query', query] \ 'options': ['+m', '-x', '--tiebreak=index', '--header-lines=1', '--ansi', '-d', '\t', '--with-nth', '3..', '-n', '2,1..2', '--prompt', 'Buf> ', '--query', query, '--preview-window', '+{2}-5']
\}, args) \}, args)
endfunction endfunction
@@ -744,6 +744,7 @@ function! fzf#vim#grep(grep_command, has_column, ...)
\ 'column': a:has_column, \ 'column': a:has_column,
\ 'options': ['--ansi', '--prompt', capname.'> ', \ 'options': ['--ansi', '--prompt', capname.'> ',
\ '--multi', '--bind', 'alt-a:select-all,alt-d:deselect-all', \ '--multi', '--bind', 'alt-a:select-all,alt-d:deselect-all',
\ '--delimiter', ':', '--preview-window', '+{2}-5',
\ '--color', 'hl:4,hl+:12'] \ '--color', 'hl:4,hl+:12']
\} \}
function! opts.sink(lines) function! opts.sink(lines)
@@ -815,7 +816,7 @@ function! fzf#vim#buffer_tags(query, ...)
return s:fzf('btags', { return s:fzf('btags', {
\ 'source': s:btags_source(tag_cmds), \ 'source': s:btags_source(tag_cmds),
\ 'sink*': s:function('s:btags_sink'), \ 'sink*': s:function('s:btags_sink'),
\ 'options': s:reverse_list(['-m', '-d', '\t', '--with-nth', '1,4..', '-n', '1', '--prompt', 'BTags> ', '--query', a:query])}, args) \ 'options': s:reverse_list(['-m', '-d', '\t', '--with-nth', '1,4..', '-n', '1', '--prompt', 'BTags> ', '--query', a:query, '--preview-window', '+{3}-5'])}, args)
catch catch
return s:warn(v:exception) return s:warn(v:exception)
endtry endtry
@@ -1173,7 +1174,7 @@ function! s:commits(buffer_local, args)
if !s:is_win && &columns > s:wide if !s:is_win && &columns > s:wide
call extend(options.options, call extend(options.options,
\ ['--preview', 'echo {} | grep -o "[a-f0-9]\{7,\}" | head -1 | xargs git show --format=format: --color=always | head -200']) \ ['--preview', 'echo {} | grep -o "[a-f0-9]\{7,\}" | head -1 | xargs git show --format=format: --color=always | head -1000'])
endif endif
return s:fzf(a:buffer_local ? 'bcommits' : 'commits', options, a:args) return s:fzf(a:buffer_local ? 'bcommits' : 'commits', options, a:args)

View File

@@ -39,23 +39,9 @@ if [ -z "$CENTER" ]; then
CENTER=0 CENTER=0
fi fi
if [ -n "$FZF_PREVIEW_LINES" ]; then
LINES=$FZF_PREVIEW_LINES
else
if [ -r /dev/tty ]; then
LINES=$(stty size < /dev/tty | awk '{print $1}')
else
LINES=40
fi
fi
FIRST=$(($CENTER-$LINES/3))
FIRST=$(($FIRST < 1 ? 1 : $FIRST))
LAST=$((${FIRST}+${LINES}-1))
if [ -z "$FZF_PREVIEW_COMMAND" ] && command -v bat > /dev/null; then if [ -z "$FZF_PREVIEW_COMMAND" ] && command -v bat > /dev/null; then
bat --style="${BAT_STYLE:-numbers}" --color=always --pager=never \ bat --style="${BAT_STYLE:-numbers}" --color=always --pager=never \
--line-range=$FIRST:$LAST --highlight-line=$CENTER "$FILE" --highlight-line=$CENTER "$FILE"
exit $? exit $?
fi fi
@@ -63,7 +49,7 @@ DEFAULT_COMMAND="highlight -O ansi -l {} || coderay {} || rougify {} || cat {}"
CMD=${FZF_PREVIEW_COMMAND:-$DEFAULT_COMMAND} CMD=${FZF_PREVIEW_COMMAND:-$DEFAULT_COMMAND}
CMD=${CMD//{\}/$(printf %q "$FILE")} CMD=${CMD//{\}/$(printf %q "$FILE")}
eval "$CMD" 2> /dev/null | awk "NR >= $FIRST && NR <= $LAST { \ eval "$CMD" 2> /dev/null | awk "{ \
if (NR == $CENTER) \ if (NR == $CENTER) \
{ gsub(/\x1b[[0-9;]*m/, \"&$REVERSE\"); printf(\"$REVERSE%s\n$RESET\", \$0); } \ { gsub(/\x1b[[0-9;]*m/, \"&$REVERSE\"); printf(\"$REVERSE%s\n$RESET\", \$0); } \
else printf(\"$RESET%s\n\", \$0); \ else printf(\"$RESET%s\n\", \$0); \

View File

@@ -1,4 +1,4 @@
fzf-vim.txt fzf-vim Last change: July 27 2020 fzf-vim.txt fzf-vim Last change: August 12 2020
FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-toc* FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-toc*
============================================================================== ==============================================================================
@@ -90,11 +90,13 @@ so you can omit it if you use a plugin manager that doesn't support hooks.
< Dependencies >______________________________________________________________~ < Dependencies >______________________________________________________________~
*fzf-vim-dependencies* *fzf-vim-dependencies*
- {fzf}{1} 0.22.0 or above
- For syntax-highlighted preview, install {bat}{5} - For syntax-highlighted preview, install {bat}{5}
- `Ag` requires {The Silver Searcher (ag)}{6} - `Ag` requires {The Silver Searcher (ag)}{6}
- `Rg` requires {ripgrep (rg)}{7} - `Rg` requires {ripgrep (rg)}{7}
- `Tags` and `Helptags` require Perl - `Tags` and `Helptags` require Perl
{1} https://github.com/junegunn/fzf
{5} https://github.com/sharkdp/bat {5} https://github.com/sharkdp/bat
{6} https://github.com/ggreer/the_silver_searcher {6} https://github.com/ggreer/the_silver_searcher
{7} https://github.com/BurntSushi/ripgrep {7} https://github.com/BurntSushi/ripgrep

View File

@@ -51,7 +51,7 @@ 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), <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>, <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! -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! -bar -bang -nargs=? -complete=buffer Buffers call fzf#vim#buffers(<q-args>, s:p(<bang>0, { "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)',
@@ -59,7 +59,7 @@ call s:defs([
\'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), <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), <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}", "options": ["-d", "\t"] }), <bang>0)', \'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(<q-args>, s:p(<bang>0, { "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)',