From cb6ea5e06fea934d309db6bffb9d58f9dcf97765 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 26 Aug 2026 22:47:46 +0900 Subject: [PATCH] Prefer a relative entry over tilde expansion in s:in_dir Only :History reports a path as '~/...', but every command went through the same branch, so an entry under a directory literally named '~' resolved to the home directory and Show opened the wrong file or nothing. Resolve against the run directory first and fall back to the home reading. --- autoload/fzf/vim.vim | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index a80e949..47413b6 100755 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -637,14 +637,17 @@ endfunction " fzf#run restores the working directory while fzf runs and only re-applies " 'dir' for the sink, so a relative entry has to be resolved here function! s:in_dir(dir, path) abort - " filereadable does not expand a leading tilde, which :History reports - if a:path =~# '^\~' - return fnamemodify(a:path, ':p') - endif if empty(a:dir) || a:path =~# '^/' || a:path =~# '^\a:[\\/]' return a:path endif - return fnamemodify(expand(escape(a:dir, '[]*?{}')), ':p').a:path + let path = fnamemodify(expand(escape(a:dir, '[]*?{}')), ':p').a:path + " :History reports a path under the home directory as '~/...', which + " filereadable does not expand. Other commands can emit a relative path + " under a directory named '~', so prefer that reading when it exists + if a:path =~# '^\~' && !filereadable(path) + return fnamemodify(a:path, ':p') + endif + return path endfunction " Shows the entry without closing fzf. The callback can fire while the fzf