Inside the file ~/.zshenv I export this value for the MANSECT environment variable (the value is taken from /etc/manpath.config):

export MANSECT=1:n:l:8:3:2:3posix:3pm:3perl:5:4:9:6:7

This variable seems to control the order of the sections in which $ man searches for a manpage, when you don't specifiy one.

As an example, this command opens the printf manpage in the first section of the manual:

$ MANSECT=1:2:3 man printf

Because I didn't specify the section number I was interested in, and because the section 1 comes before the section 3 inside $MANSECT.

In contrast, this command opens the printf manpage in the third section of the manual:

MANSECT=3:2:1 man printf

Because the section 3 comes before the section 1 in $MANSECT.

Now, according to Vim's help (:help manpager.vim), Vim can be used as a manpager:

export MANPAGER="vim -M +MANPAGER -"

If I start Vim with the $ vim command, and ask for the value of $MANSECT, I get the original value (the one exported in the shell):

$ export MANSECT=1:2:3
$ export MANPAGER="vim -M +MANPAGER -"
$ vim
:echo $MANSECT

The last :echo correctly prints 1:2:3 on Vim's command line.

But if I start Vim with the $ man command:

$ export MANSECT=1:2:3
$ export MANPAGER="vim -M +MANPAGER -"
$ man man
:echo $MANSECT

The last :echo prints only 1 on Vim's command line, instead of 1:2:3.

Some information about my machine:

  • vim --version: VIM - Vi IMproved 8.1 Included patches: 1-495
  • man --version: 2.7.5
  • Operating system: Ubuntu 16.04.5 LTS
  • Terminal emulator: rxvt-unicode v9.22
  • Terminal multiplexer: tmux 2.8
  • $TERM: tmux-256color
  • Shell: zsh 5.6.2-dev-0 (x86_64-pc-linux-gnu)

Is it possible to prevent $MANSECT from being altered when using Vim as a manpager?

The reason I ask this question is because the Neovim man plugin suffers from an issue where you can't open a manpage outside the first section of the manual if you have started Neovim as a manpager:

$ export MANSECT=1:n:l:8:3:2:3posix:3pm:3perl:5:4:9:6:7
$ export MANPAGER='nvim +Man!'
$ man man
:Man mount

The last command raises the following error:

man.vim: command error (11) man -w mount: No manual entry for mount
See 'man 7 undocumented' for help when manual pages are not available.

This is due to $MANSECT having been truncated to the first section number (1), and the manpage for $ mount is in the section 8.

  • Try: declare -r MANSECT=1:n:l:8:3:2:3posix:3pm:3perl:5:4:9:6:7 export MANSECT – pacmanwa Oct 26 '18 at 15:35
  • @pacmanwa Thank you very much for the comment. I just tried the command, but unfortunately, the value of $MANSECT is still truncated inside (Neo)Vim. – user938271 Oct 26 '18 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.