3

:h manpager describes how to use vim as a manpager:

Works on:

  - Linux
  - Mac OS
  - FreeBSD
  - Cygwin
  - Win 10 under Bash

Untested:

  - Amiga OS
  - BeOS
  - OS/2

For bash,zsh,ksh or dash by adding to the config file (.bashrc,.zshrc, ...)

    export MANPAGER="env MAN_PN=1 vim -M +MANPAGER -"

The line above works for me on Linux (Debian 9.2), but the same setting on a Mac (10.11 El Capitan) causes the following error every time I invoke man:

Error detected while processing function <SNR>57_MANPAGER:
line   16:
E684: list index out of range: 2
E15: Invalid expression: page_sec[2] page_sec[1]
Press ENTER or type command to continue

Question 1: Is this a bug?

Should I file a bug report with vim?

EDIT: This appears to be a bug in the $VIMRUNTIME/plugin/manpager.vim plugin. Line 18 reads:

let manpage = matchstr( getline(1), '^' . pagesec_pattern )

It can be fixed by replacing getline(1) with getline(nextnonblank(1)).

Question 2: Is there a workaround?

I've found alternate settings for the MANPAGER environment variable on /r/vim and this StackExchange that make it work on macOS, but both of them cause navigation via <C-]> to break and give the folllowing output:

sh: -c: line 0: syntax error near unexpected token `||'
sh: -c: line 0: `(cd '/usr/share/man' && (echo ".ll 12.1i"; echo ".nr LL 12.1i"; /bin/cat '/usr/share/man/man1/vimtutor.1') | /usr/bin/tbl | /usr/bin/groff -Wall -mtty-char -Tascii -mandoc -c | ( || true))'
Error executing formatting or display command.
System command (cd '/usr/share/man' && (echo ".ll 12.1i"; echo ".nr LL 12.1i"; /bin/cat '/usr/share/man/man1/vimtutor.1') | /usr/bin/tbl | /usr/bin/groff -Wall -mtty-char -Tascii -mandoc -c | ( || true)) exited with status 512.
No entry for vimtutor in section 1 of the manual

EDIT: Even with the fix described above, I'm continuing to get this error when navigating between man pages. It looks like it's being caused by the ( || true) statement in the shell command, but I'm not sure where that shell command is being invoked from.

Does anyone know of a fully working solution?


Running vim 8.0.596

$ vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled May  8 2017 15:44:54)
MacOS X (unix) version
Included patches: 1-596
  • Is this a bug -> Possibly? The code that errors out is in $VIMRUNTIME/plugin/manpager.vim. It's not very long or complicated. Adding some strategic echos might help debug the problem. – Martin Tournoij Nov 1 '17 at 11:07
  • There's a line in the s:MANPAGER() function that looks like this: let manpage = matchstr( getline(1), '^' . pagesec_pattern ). getline(1) is returning an empty string, which I think is what's causing the problem. Beyond that, I don't really know how to diagnose it. Any chance you could point me in the right direction? – Ryan Lue Nov 2 '17 at 10:51
  • I think the format of the manpages might be different on macOS? I don't have a mac machine myself, so unfortunately I can't test it. – Martin Tournoij Nov 2 '17 at 11:00
  • what does the first line look like? BTW: You should report that to the plugin maintainer (or if he is unresponsive to vim-dev) – Christian Brabandt Nov 2 '17 at 19:36
  • Thanks for helping me take the next step, @ChristianBrabandt. The first line of a manpage is actually blank on a Mac (or at least on my machine); the second is the one that contains the manpage name. Changing it to getline(nextnonblank(1)) made it work. I'll shoot out an email to the maintainer now. (Unfortunately, I'm still getting the same error as above when trying to navigate with <C-]>...) – Ryan Lue Nov 3 '17 at 1:50
1
+50

This was identified as a bug and has been (to the best of my knowledge) resolved thanks to the hard work of @ChristianBrabandt and others.

-1

just put this:

manvim() { vim -c "Man $1" -c 'silent! only'; }

in your bashrc or bash_profile. Then source the file & then use:

$ manvim 'man page name' 

without the quotes.

  • 2
    FYI, :Man is provided by the man.vim ftplugin. That file must be sourced for the command to be defined. There are two ways to do that: 1) add -c 'set ft=man' to the vim arguments above, or 2) execute 'source ' . $VIMRUNTIME . '/ftplugin/man.vim' in your vimrc. NOTE: This approach will not work if MANPAGER is set (you'll get the sh: -c: line 0: syntax error near unexpected token `||' error mentioned in the question). This appears to be a bug, and I've notified the author via email. – Ryan Lue Nov 8 '17 at 4:20

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.