From d86d9759e5311895ef00383bcb5a0375ac53b97e Mon Sep 17 00:00:00 2001 From: Barrett Ruth <62671086+barrettruth@users.noreply.github.com> Date: Tue, 14 Apr 2026 18:08:09 -0400 Subject: [PATCH] fix(gf): handle local `file:` URI paths #38915 Problem: `gf` and `` treat `file:/absolute/path` as a literal path and open `file:/...` instead of the local file. Solution: Strip the local `file:` prefix before path resolution in the hyperlink path code. (cherry picked from commit e827c3b6481b84e503ab0a4325ada4b6631a602f) --- src/nvim/file_search.c | 7 +++++++ test/functional/core/path_spec.lua | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 1cd747a08f..b9298095e8 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -1759,6 +1759,13 @@ char *find_file_name_in_path(char *ptr, size_t len, int options, long count, cha return NULL; } + if ((options & FNAME_HYP) && len > 6 && strncmp(ptr, "file:/", + 6) == 0 && !vim_ispathsep(ptr[6])) { + size_t off = path_has_drive_letter(ptr + 6, len - 6) ? 6 : 5; + ptr += off; + len -= off; + } + if ((options & FNAME_INCL) && *curbuf->b_p_inex != NUL) { tofree = eval_includeexpr(ptr, len); if (tofree != NULL) { diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index e8c7578306..9128cd8aab 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -160,6 +160,17 @@ describe('file search', function() ) end) + it('gf/ handles local file: paths', function() + local path = fn.fnamemodify(join_path(testdir, 'gf-target.txt'), ':p'):gsub('\\', '/') + local uri = 'file:' .. (is_os('win') and '/' or '') .. path + write_file(path, '') + insert(uri) + command('norm! 0') + eq(path, eval('expand("")')) + feed('gf') + eq(path, fn.fnamemodify(eval('expand("%:p")'), ':p'):gsub('\\', '/')) + end) + ---@param funcname 'finddir' | 'findfile' local function test_find_func(funcname, folder, item) local d = join_path(testdir, folder)