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).
This commit is contained in:
Shubh
2026-08-23 20:58:22 +05:30
committed by GitHub
parent 042e337861
commit bca9c4afa7
2 changed files with 21 additions and 5 deletions

View File

@@ -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

View File

@@ -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({