From bca9c4afa77fc8396d0ab63511bfedb9dcdd5c89 Mon Sep 17 00:00:00 2001 From: Shubh Date: Sun, 23 Aug 2026 20:58:22 +0530 Subject: [PATCH] fix(man): allow :Man to open by absolute path #41401 Problem: man -w echoes any existent file back unchanged. :Man rejected all such paths, so :Man /usr/share/man/man1/bash.1 failed even for real man pages. Solution: Accept an echoed path when it looks like a man page (.../man1/foo.1). --- runtime/lua/man.lua | 13 ++++++++----- test/functional/plugin/man_spec.lua | 13 +++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/runtime/lua/man.lua b/runtime/lua/man.lua index 1ad53b1c24..2fa054a855 100644 --- a/runtime/lua/man.lua +++ b/runtime/lua/man.lua @@ -257,12 +257,15 @@ function M._match_manpage_path(paths, name, sect) return end - -- `man -w /some/path` will return `/some/path` for any existent file, which - -- stops us from actually determining if a path has a corresponding man file. - -- Since `:Man /some/path/to/man/file` isn't supported anyway, we should just - -- error out here if we detect this is the case. + -- `man -w /some/path` echoes the input for any existent file. Accept only + -- paths that look like a man page (`.../man1/bash.1`). #30873 if sect == '' and #paths == 1 and paths[1] == name then - return + local tail = vim.fs.basename(name) + local parent = vim.fs.basename(vim.fs.dirname(name)) + if not (parent:find('^man') and tail:find('%.%d')) then + return + end + return name end -- find any that match the specified name diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index 40b0dac81f..17d9e6cd6f 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -267,6 +267,19 @@ describe(':Man', function() end) end + eq( + '/usr/share/man/man1/bash.1', + _test({ '/usr/share/man/man1/bash.1' }, '/usr/share/man/man1/bash.1') + ) + + eq( + '/usr/share/man/man3/strlen.3.gz', + _test({ '/usr/share/man/man3/strlen.3.gz' }, '/usr/share/man/man3/strlen.3.gz') + ) + + eq(nil, _test({ '/tmp/not-a-manpage' }, '/tmp/not-a-manpage')) + eq(nil, _test({ '/tmp/T10.1' }, '/tmp/T10.1')) + eq( '/usr/share/man/man3/strcpy.3', _test({