mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-06 04:34:26 +08:00
[Jumps] Support preview window (#1553)
Require fzf 0.54.0 or above Signed-off-by: zeminzhou <zhouzemin@pingcap.cn> Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>
This commit is contained in:
3
.github/ISSUE_TEMPLATE.md
vendored
3
.github/ISSUE_TEMPLATE.md
vendored
@@ -2,7 +2,8 @@
|
||||
|
||||
<!-- Check all that apply [x] -->
|
||||
|
||||
- [ ] I have fzf 0.30.0 or above
|
||||
- [ ] I have fzf 0.54.0 or above
|
||||
- `:echo system(fzf#exec() .. ' --version')`
|
||||
- [ ] I have read through https://github.com/junegunn/fzf.vim/blob/master/README.md
|
||||
- [ ] I have read through https://github.com/junegunn/fzf/blob/master/README-VIM.md
|
||||
- [ ] I have read through the manual page of fzf (`man fzf`)
|
||||
|
||||
@@ -64,7 +64,7 @@ so you can omit it if you use a plugin manager that doesn't support hooks.
|
||||
|
||||
### Dependencies
|
||||
|
||||
- [fzf][fzf-main] 0.41.1 or above
|
||||
- [fzf][fzf-main] 0.54.0 or above
|
||||
- For syntax-highlighted preview, install [bat](https://github.com/sharkdp/bat)
|
||||
- If [delta](https://github.com/dandavison/delta) is available, `GF?`,
|
||||
`Commits` and `BCommits` will use it to format `git diff` output.
|
||||
|
||||
@@ -1337,37 +1337,52 @@ endfunction
|
||||
" Jumps
|
||||
" ------------------------------------------------------------------
|
||||
function! s:jump_format(line)
|
||||
return substitute(a:line, '[0-9]\+', '\=s:yellow(submatch(0), "Number")', '')
|
||||
let line = substitute(a:line, '[0-9]\+', '\=s:yellow(submatch(0), "Number")', '')
|
||||
let line = substitute(line, '\s.\{-}\ze:[0-9]\+:', '\=s:green(submatch(0), "Directory")', '')
|
||||
let line = substitute(line, '\%(:[0-9]\+\)\+:', '\=s:black(submatch(0), "NonText")', '')
|
||||
return line
|
||||
endfunction
|
||||
|
||||
function! s:jump_sink(lines)
|
||||
if len(a:lines) < 2
|
||||
return
|
||||
endif
|
||||
call s:action_for(a:lines[0])
|
||||
let idx = index(s:jumplist, a:lines[1])
|
||||
if idx == -1
|
||||
return
|
||||
endif
|
||||
let current = match(s:jumplist, '\v^\s*\>')
|
||||
let delta = idx - current
|
||||
keepjumps call s:action_for(a:lines[0])
|
||||
let idx = str2nr(a:lines[1])
|
||||
let delta = idx - s:jump_current - 1
|
||||
if delta < 0
|
||||
execute 'normal! ' . -delta . "\<C-O>"
|
||||
else
|
||||
execute 'normal! ' . delta . "\<C-I>"
|
||||
endif
|
||||
normal! zvzz
|
||||
endfunction
|
||||
|
||||
function! fzf#vim#jumps(...)
|
||||
redir => cout
|
||||
silent jumps
|
||||
redir END
|
||||
let s:jumplist = split(cout, '\n')
|
||||
let current = -match(s:jumplist, '\v^\s*\>')
|
||||
let [jumps, pos] = getjumplist()
|
||||
if empty(jumps)
|
||||
return s:warn('No jumps')
|
||||
endif
|
||||
let s:jumplist = []
|
||||
for idx in range(len(jumps))
|
||||
let jump = jumps[idx]
|
||||
let loc = expand('#'.jump.bufnr.':p:~:.')
|
||||
if empty(loc)
|
||||
let loc = '[No Name]'
|
||||
endif
|
||||
let loc .= ':'.jump.lnum
|
||||
if jump.col
|
||||
let loc .= ':'.jump.col
|
||||
endif
|
||||
let line = printf('%-2d %s: %s', idx+1, loc, getbufoneline(jump.bufnr, jump.lnum))
|
||||
call add(s:jumplist, line)
|
||||
endfor
|
||||
let s:jump_current = pos
|
||||
let current = -pos-1
|
||||
return s:fzf('jumps', {
|
||||
\ 'source' : extend(s:jumplist[0:0], map(s:jumplist[1:], 's:jump_format(v:val)')),
|
||||
\ 'source' : map(s:jumplist, 's:jump_format(v:val)'),
|
||||
\ 'sink*' : s:function('s:jump_sink'),
|
||||
\ 'options' : '+m -x --ansi --tiebreak=index --cycle --scroll-off 999 --sync --bind start:pos:'.current.' --tac --header-lines 1 --tiebreak=begin --prompt "Jumps> "',
|
||||
\ 'options' : ['+m', '-x', '--ansi', '--tiebreak=index', '--cycle', '--scroll-off=999', '--sync', '--bind', 'start:pos('.current.')+offset-middle', '--tac', '--tiebreak=begin', '--prompt', 'Jumps> ', '--preview-window', '+{3}-/2', '--tabstop=2', '--delimiter', '[:\s]+'],
|
||||
\ }, a:000)
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -47,7 +47,9 @@ fi
|
||||
|
||||
FILE="${FILE/#\~\//$HOME/}"
|
||||
if [ ! -r "$FILE" ]; then
|
||||
echo "File not found ${FILE}"
|
||||
if [[ "${INPUT[0]}" != '[No Name]' ]]; then
|
||||
echo "File not found ${FILE}"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ so you can omit it if you use a plugin manager that doesn't support hooks.
|
||||
< Dependencies >______________________________________________________________~
|
||||
*fzf-vim-dependencies*
|
||||
|
||||
- {fzf}{1} 0.41.1 or above
|
||||
- {fzf}{1} 0.54.0 or above
|
||||
- For syntax-highlighted preview, install {bat}{4}
|
||||
- If {delta}{5} is available, `GF?`, `Commits` and `BCommits` will use it to
|
||||
format `git diff` output.
|
||||
|
||||
@@ -66,7 +66,7 @@ call s:defs([
|
||||
\'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(<q-args>, fzf#vim#with_preview({ "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 Jumps call fzf#vim#jumps(<bang>0)',
|
||||
\'command! -bar -bang Jumps call fzf#vim#jumps(fzf#vim#with_preview({ "placeholder": "{2..4}"}), <bang>0)',
|
||||
\'command! -bar -bang Marks call fzf#vim#marks(<bang>0)',
|
||||
\'command! -bar -bang Changes call fzf#vim#changes(<bang>0)',
|
||||
\'command! -bar -bang Helptags call fzf#vim#helptags(fzf#vim#with_preview({ "placeholder": "--tag {2}:{3}:{4}" }), <bang>0)',
|
||||
|
||||
Reference in New Issue
Block a user