From 5d87ac1fe8d729f116bda2f90a7211ad309ddf5a Mon Sep 17 00:00:00 2001 From: Kevin Ushey Date: Sun, 4 Jun 2023 00:21:37 -0700 Subject: [PATCH] Add :Jumps (#710) Co-authored-by: Junegunn Choi --- README.md | 1 + autoload/fzf/vim.vim | 41 +++++++++++++++++++++++++++++++++++++++++ doc/fzf-vim.txt | 3 ++- plugin/fzf.vim | 1 + 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2fe1fd9..0e257ad 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ Commands | `:Tags [QUERY]` | Tags in the project (`ctags -R`) | | `:BTags [QUERY]` | Tags in the current buffer | | `:Marks` | Marks | +| `:Jumps` | Jumps | | `:Windows` | Windows | | `:Locate PATTERN` | `locate` command output | | `:History` | `v:oldfiles` and open buffers | diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index 2566f56..05b8586 100755 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -1169,6 +1169,47 @@ function! fzf#vim#marks(...) \ 'options': '+m -x --ansi --tiebreak=index --header-lines 1 --tiebreak=begin --prompt "Marks> "'}, a:000) endfunction +" ------------------------------------------------------------------ +" Jumps +" ------------------------------------------------------------------ +function! s:jump_format(line) + return substitute(a:line, '[0-9]\+', '\=s:yellow(submatch(0), "Number")', '') +endfunction + +function! s:jump_sink(lines) + if len(a:lines) < 2 + return + endif + let cmd = s:action_for(a:lines[0]) + if !empty(cmd) + execute 'silent' cmd + endif + let idx = index(s:jumplist, a:lines[1]) + if idx == -1 + return + endif + let current = match(s:jumplist, '\v^\s*\>') + let delta = idx - current + if delta < 0 + execute 'normal! ' . -delta . "\" + else + execute 'normal! ' . delta . "\" + endif +endfunction + +function! fzf#vim#jumps(...) + redir => cout + silent jumps + redir END + let s:jumplist = split(cout, '\n') + let current = -match(s:jumplist, '\v^\s*\>') + return s:fzf('jumps', { + \ 'source' : extend(s:jumplist[0:0], map(s:jumplist[1:], '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> "', + \ }, a:000) +endfunction + " ------------------------------------------------------------------ " Help tags " ------------------------------------------------------------------ diff --git a/doc/fzf-vim.txt b/doc/fzf-vim.txt index 82bdbd7..c6d62a7 100644 --- a/doc/fzf-vim.txt +++ b/doc/fzf-vim.txt @@ -107,7 +107,7 @@ COMMANDS *fzf-vim-commands* ============================================================================== *:Files* *:GFiles* *:Buffers* *:Colors* *:Ag* *:Rg* *:RG* *:Lines* *:BLines* *:Tags* *:BTags* *:Marks* - *:Windows* *:Locate* *:History* *:Snippets* *:Commits* *:BCommits* *:Commands* *:Maps* + *:Jumps* *:Windows* *:Locate* *:History* *:Snippets* *:Commits* *:BCommits* *:Commands* *:Maps* *:Helptags* *:Filetypes* -----------------------+-------------------------------------------------------------------------------------- @@ -126,6 +126,7 @@ COMMANDS *fzf-vim-commands* `:Tags [QUERY]` | Tags in the project ( `ctags -R` ) `:BTags [QUERY]` | Tags in the current buffer `:Marks` | Marks + `:Jumps` | Jumps `:Windows` | Windows `:Locate PATTERN` | `locate` command output `:History` | `v:oldfiles` and open buffers diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 1466fce..c73931b 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -60,6 +60,7 @@ call s:defs([ \'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(, fzf#vim#with_preview({ "placeholder": "{2}:{3..}" }), 0)', \'command! -bar -bang Snippets call fzf#vim#snippets(0)', \'command! -bar -bang Commands call fzf#vim#commands(0)', +\'command! -bar -bang Jumps call fzf#vim#jumps(0)', \'command! -bar -bang Marks call fzf#vim#marks(0)', \'command! -bar -bang Helptags call fzf#vim#helptags(fzf#vim#with_preview({ "placeholder": "--tag {2}:{3}:{4}" }), 0)', \'command! -bar -bang Windows call fzf#vim#windows(0)',