How to make zsh pass the manual section to the man command when the `separate-sections` style is set

autocompletezsh

When asking for a completion by pressing Tab on the zsh command line, the matches can be grouped according to their tag provided that the group-name style is set to an empty string:

autoload -Uz compinit
compinit
zstyle ':completion:*' menu select
zstyle ':completion:*' group-name ''
zstyle ':completion:*:descriptions' format '%d'

In the case of the $ man command, the matches can be divided further if the separate-sections style is set to true for the manuals tag:

autoload -Uz compinit
compinit
zstyle ':completion:*' menu select
zstyle ':completion:*' group-name ''
zstyle ':completion:*:descriptions' format '%d'
zstyle ':completion:*:manuals' separate-sections true

As a result, if I press Tab after $ man write, the completion system suggests these matches:

$ man write
manual page, section 1 (general commands)
write
manual page, section 2 (system calls)
write   writev

And if I select the write match in the first list, $ man opens the write page in the first section of the manual.

But if I select the write match in the second list, $ man still opens the write page in the first section, while the description of the list mentions the second section of the manual.

Is it possible to make zsh pass the relevant manual section to the man command when the separate-sections style is set?

I'm using zsh 5.6.2-dev-0 (x86_64-pc-linux-gnu).

Best Answer

You need to add simply the following:

zstyle ':completion:*' insert-sections true

This is unfortunately not documented, but you can see it here from the code: https://github.com/zsh-users/zsh/blob/8becb893579af0ca41617a15d3afcbea588fe621/Completion/Unix/Command/_man#L448

I tested it and it works.

Related Question