From 506f0167b48be9b6e1c0362607421a88d142017b Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Mon, 28 Sep 2026 22:50:13 +0900 Subject: [PATCH] Leave the buffer and the cursor as they were for a refused address Nothing was opened, so 'normal! ^zvzz' had no business moving the cursor in whatever buffer the user was in. An address that no longer matches did open the file, though, so that case still opens the fold it landed in and centres it. A multi-selection whose other entries were refused still owes the key its action, and the loop opened the survivor in the starting window, so that window goes back as it was first. --- autoload/fzf/vim.vim | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index e58fc77..29ee88a 100755 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -1748,7 +1748,7 @@ function! s:btags_sink(from, lines) normal! g`' " Because 'listproc' will use 'cfirst' to go to the first item in the list call s:fill_quickfix('btags', qfl) - else + elseif len(qfl) == 1 normal! zvzz endif if !empty(tagname) @@ -1799,6 +1799,7 @@ function! s:tags_sink(from, lines) let tagname = '' let qfl = [] + let opened = 0 let [key; list] = a:lines try @@ -1822,6 +1823,7 @@ function! s:tags_sink(from, lines) else call s:open(abspath) endif + let opened = 1 call s:execute_tag_address(excmd) call add(qfl, {'filename': expand('%'), 'lnum': line('.'), 'text': getline('.')}) if empty(tagname) @@ -1848,7 +1850,18 @@ function! s:tags_sink(from, lines) call s:action_for(key, qfl[0].filename, 1) call s:fill_quickfix('tags', qfl) - else + elseif opened + " Entries opened in the loop take the action only when one was selected, so + " the last one standing of a multi-selection still owes the key its action. + " The loop opened it in the starting window, which goes back as it was first + if len(qfl) == 1 && len(list) > 1 + call s:execute_silent('b '.buf) + call winrestview(view) + call s:action_for(key, qfl[0].filename) + call cursor(qfl[0].lnum, 1) + endif + " An address that no longer matches still opened the file, so open the fold + " it landed in and centre it normal! ^zvzz endif if !empty(tagname)