feat(man): allow opening pages in current window (#27861)

With :hide modifier, open page in current window.
This commit is contained in:
Tomasz N 2024-03-16 02:00:25 +01:00 committed by GitHub
parent 102a72a21e
commit 25e7299707
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 4 deletions

View File

@ -626,8 +626,10 @@ Man Open the manpage for the <cWORD> (man buffers)
or <cword> (non-man buffers) under the cursor.
Man! Display the current buffer contents as a manpage.
|:Man| accepts command modifiers. For example, to use a vertical split: >
|:Man| accepts command modifiers. For example, to use a vertical split: >vim
:vertical Man printf
To reuse the current window: >vim
:hide Man printf
Local mappings:
K or CTRL-] Jump to the manpage for the <cWORD> under the
@ -647,14 +649,14 @@ Variables:
empty. Enabled by default. Set |FALSE| to enable soft
wrapping.
To use Nvim as a manpager: >
To use Nvim as a manpager: >sh
export MANPAGER='nvim +Man!'
Note that when running `man` from the shell and with that `MANPAGER` in your
environment, `man` will pre-format the manpage using `groff`. Thus, Nvim
will inevitably display the manual page as it was passed to it from stdin. One
of the caveats of this is that the width will _always_ be hard-wrapped and not
soft wrapped as with `g:man_hardwrap=0`. You can set in your environment: >
soft wrapped as with `g:man_hardwrap=0`. You can set in your environment: >sh
export MANWIDTH=999
So `groff`'s pre-formatting output will be the same as with `g:man_hardwrap=0` i.e soft-wrapped.
@ -662,6 +664,10 @@ So `groff`'s pre-formatting output will be the same as with `g:man_hardwrap=0` i
To disable bold highlighting: >
:highlight link manBold Normal
An alternative to using `MANPAGER` in shell can be redefined `man`, for example: >sh
man() {
nvim "+hide Man $1"
}
MARKDOWN *ft-markdown-plugin*

View File

@ -254,6 +254,8 @@ The following new APIs and features were added.
node emit a hyperlink. Hyperlinks are UI specific: in the TUI, the OSC 8
control sequence is used.
• |:Man| now supports `:hide` modifier to open page in the current window.
• |vim.ui.open()| opens URIs using the system default handler (macOS `open`,
Windows `explorer`, Linux `xdg-open`, etc.)

View File

@ -716,7 +716,7 @@ function M.open_page(count, smods, args)
local target = ('%s(%s)'):format(name, sect)
local ok, ret = pcall(function()
if smods.tab == -1 and find_man() then
if smods.hide or (smods.tab == -1 and find_man()) then
vim.cmd.tag({ target, mods = { silent = true, keepalt = true } })
else
smods.silent = true