From a2ed9fb88584f6096f19d4e408b202732a6463f6 Mon Sep 17 00:00:00 2001 From: Scott Lai <32601233+scottdlai@users.noreply.github.com> Date: Sat, 7 Jun 2025 18:48:17 -0700 Subject: [PATCH] Add :BMarks command (#1593) And allow passing arguments of :marks to :Marks command. Close #1158. Co-authored-by: Junegunn Choi --- README.md | 1 + autoload/fzf/vim.vim | 18 ++++++++++++++---- doc/fzf-vim.txt | 7 ++++--- plugin/fzf.vim | 3 ++- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1b1fc6f..52d8f57 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ Commands | `:BTags [QUERY]` | Tags in the current buffer | | `:Changes` | Changelist across all open buffers | | `:Marks` | Marks | +| `:BMarks` | Marks in the current buffer | | `:Jumps` | Jumps | | `:Windows` | Windows | | `:Locate PATTERN` | `locate` command output | diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index e2af9d0..310acac 100755 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -1362,15 +1362,25 @@ function! s:mark_sink(lines) execute 'normal! `'.matchstr(a:lines[1], '\S').'zz' endfunction -function! fzf#vim#marks(...) +function! fzf#vim#marks(...) abort + let [initial_marks, extra] = (a:0 && type(a:1) == type('')) ? + \ [a:1, a:000[1:]] : ['', a:000] + redir => cout - silent marks + execute 'silent! marks' initial_marks redir END + let list = split(cout, "\n") + + " If first line is not the expected header, no marks found + if empty(list) || list[0] =~# '^E' + return s:warn('No marks found') + endif + return s:fzf('marks', { - \ 'source': extend(list[0:0], map(list[1:], 's:format_mark(v:val)')), + \ 'source': extend(list[0:0], map(list[1:], 's:format_mark(v:val)')), \ 'sink*': s:function('s:mark_sink'), - \ 'options': '+m -x --ansi --tiebreak=index --header-lines 1 --tiebreak=begin --prompt "Marks> "'}, a:000) + \ 'options': '+m -x --ansi --tiebreak=index --header-lines 1 --tiebreak=begin --prompt "Marks> "'}, extra) endfunction " ------------------------------------------------------------------ diff --git a/doc/fzf-vim.txt b/doc/fzf-vim.txt index 040a6e1..bae5ff3 100644 --- a/doc/fzf-vim.txt +++ b/doc/fzf-vim.txt @@ -1,4 +1,4 @@ -fzf-vim.txt fzf-vim Last change: March 3 2025 +fzf-vim.txt fzf-vim Last change: June 8 2025 FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-toc* ============================================================================== @@ -110,8 +110,8 @@ COMMANDS *fzf-vim-commands* ============================================================================== *:Files* *:GFiles* *:Buffers* *:Colors* *:Ag* *:Rg* *:RG* *:Lines* *:BLines* *:Tags* *:BTags* - *:Changes* *:Marks* *:Jumps* *:Windows* *:Locate* *:History* *:Snippets* *:Commits* *:BCommits* - *:Commands* *:Maps* *:Helptags* *:Filetypes* + *:Changes* *:Marks* *:BMarks* *:Jumps* *:Windows* *:Locate* *:History* *:Snippets* *:Commits* + *:BCommits* *:Commands* *:Maps* *:Helptags* *:Filetypes* -----------------------+-------------------------------------------------------------------------------------- Command | List ~ @@ -130,6 +130,7 @@ COMMANDS *fzf-vim-commands* `:BTags [QUERY]` | Tags in the current buffer `:Changes` | Changelist across all open buffers `:Marks` | Marks + `:BMarks` | Marks in the current buffer `:Jumps` | Jumps `:Windows` | Windows `:Locate PATTERN` | `locate` command output diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 2e03687..4e57f5b 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -67,7 +67,8 @@ call s:defs([ \'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(fzf#vim#with_preview({ "placeholder": "{2..4}"}), 0)', -\'command! -bar -bang Marks call fzf#vim#marks(0)', +\'command! -bar -bang -nargs=* Marks call fzf#vim#marks(, 0)', +\'command! -bar -bang -nargs=* BMarks call fzf#vim#marks("abcdefghijklmnopqrstuvwxyz", 0)', \'command! -bar -bang Changes call fzf#vim#changes(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(fzf#vim#with_preview({ "placeholder": "{2}" }), 0)',