0

I have found issues with using the MANPAGER variable in bash in order to set vim to be my manpager.

Initially I set my manpager using the method shown in :help manpager by doing:

export MANPAGER="vim -M +MANPAGER -"
man fzf

This opens up the man page but does not display ANSI colours but displays the colour codes, however if I simply run

man fzf | vim -M +MANPAGER -

The man page displays correctly with ANSI colouring enabled. I tried to use the AnsiEsc·vim plugin to display the colours by setting the MANPAGER variable as follows

export MANPAGER="vim -M +MANPAGER -c 'AnsiEsc' -"

However with this method, the ANSI codes are gone but the text does not become coloured. I have discovered that for some reason this is due to the fact that when you set the MANPAGER variable and then display the man page, your bashrc settings do not get loaded. I checked this because I have an alias in my bashrc which maps the command v to vim, therefore when I run:

man fzf | v -M +MANPAGER -

I get the same (valid) result as running the same command with vim. However when I run:

export MANPAGER="v -M +MANPAGER -"
man fzf

I get the error:

man: can't execute v: No such file or directory
man: command exited with status 255: sed -e '/^[[:space:]]*$/{ N; /^[[:space:]]*\n[[:space:]]*$/D; }' | LESS=-ix8RmPm Manual p
age fzf(1) ?ltline %lt?L/%L.:byte %bB?s/%s..?e (END):?pB %pB\%.. (press h for help or q to quit)$PM Manual page fzf(1) ?ltline
 %lt?L/%L.:byte %bB?s/%s..?e (END):?pB %pB\%.. (press h for help or q to quit)$ MAN_PN=fzf(1) v -M +MANPAGER -

Is my assumption that bashrc is not loaded when running man correct and if so is there a solution?

Thanks

  • 1
    "I have discovered that for some reason this is due to the fact that [...] your bashrc settings do not get loaded. " How did you discover that this is the reason? man doesn't run a shell to start $MANPAGER, so there's nothing to load your bashrc. – muru Nov 14 '19 at 14:09
  • Yes I agree but I assumed it based on my testing. I am basically asking why my alias does not work in the last scenario and I believe that the same reason is why the other issues exist, although I am not sure – kabeersvohra Nov 14 '19 at 14:26
  • 1
    I gave you the reason why your alias didn't work in my comment. Unless your alias is modifying Vim settings in some way, it's unrelated to the manpager problem. – muru Nov 14 '19 at 14:38
  • but surely it runs in the same shell in which I run man fzf therefore it should be able to use the alias which is in the bash shell it is called from? – kabeersvohra Nov 14 '19 at 15:12
  • 1
    "man doesn't run a shell to start $MANPAGER, so there's nothing to load your bashrc." – muru Nov 14 '19 at 15:19

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.