I'm using Vim to develop C on Linux. When I press K in order to open man page for the underlying word, I don't have control on which man section is opened. Is there a way to specify that somewhere ?

  • Wonderful suggestions: I ended up adding this set keywordprg=man\ 3\ -s to my .vimrc – stdcall Oct 16 '18 at 9:55
  • 1
    dont you want different “help” programs for different languages? – D. Ben Knoble Oct 16 '18 at 13:17
  • Never needed to launch man from within vim for something other than chapter 3 – stdcall Oct 16 '18 at 14:08
  • 2
    You might want to set this keywordprg in a ftplugin so that you keep a working K in other filetypes :h ftplugin – statox Oct 16 '18 at 14:30

Quoting from the documentation

  When 'keywordprg' is equal to "man -s", a count
  before "K" is inserted after the "-s".  If there is
  no count, the "-s" is removed.

man -s seems to be the default for the 'keywordprg' setting, so simplying using a count before typing K seems to do the trick.

(Tested successfully with 2K and 3K and the cursor being on open).

  • 3
    Damn I was 43 seconds too late! :) – statox Oct 16 '18 at 7:56

From :h K:

K           Run a program to lookup the keyword under the
            cursor.  [...]
            Special cases:
            - When 'keywordprg' is equal to "man" or starts with
              ":", a [count] before "K" is inserted after
              keywordprg and before the keyword.  For example,
              using "2K" while the cursor is on "mkdir", results
                !man 2 mkdir
            - When 'keywordprg' is equal to "man -s", a count
              before "K" is inserted after the "-s".  If there is
              no count, the "-s" is removed.

So 3K should do the trick


If you're on Linux, you're likely using mandb's man, and you can control the order in which sections are searched. See man 1 man:

If $MANSECT is set, its value is a colon-delimited list of sections and it is used to determine which manual sections to search and in what order. The default is "1 n l 8 3 2 3posix 3pm 3perl 3am 5 4 9 6 7", unless overridden by the SECTION directive in /etc/manpath.config.

So another option is to set in your shell initialisation files:

export MANSECT

Or in your vimrc:

let $MANSECT="3:3posix:3pm:3perl:3am:1:n:l:8:2:5:4:9:6:7"

(Also, depending on what you're programming, section 2 might also need a higher priority.)

(Or, as the manpage says, set system-wide in /etc/manpath.config.)

This also works for FreeBSD's man.

  • that is what -s does internally – Christian Brabandt Oct 16 '18 at 11:26
  • 1
    Indeed, -s overrides MANSECT. But this is useful for setting a priority list instead of forcing specific section (which <count>K will do), which might be more useful. For example, if open(3posix) isn't available, open(2) would still be useful (probably more so). man -s 3 open would simply ignore open(2). – muru Oct 16 '18 at 11:38

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.