: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)
withgetline(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 strategicecho
s might help debug the problem.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?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-]>
...)