`man ascii` is misaligned when using vim as a pager

manpagervim

To use Vim as a pager for man I have

export MANPAGER="/usr/share/vim/vim73/macros/manpager.sh"

in my profile. Now man pages look very good with colors and stuff. However, when trying man ascii as a way of looking at the ASCII table, I notice that the table is mis-aligned as in the screenshot below:

Messed up ASCII table

This problem doesn't happen to the default pager. When I set export MANPAGER="view -" the table is also correct, so something must be wrong with the manpager.sh script:

#!/bin/sh
sed -e 's/\x1B\[[[:digit:]]\+m//g' | col -b | \
vim \
    -c 'let no_plugin_maps = 1' \
    -c 'set nolist nomod ft=man' \
    -c 'let g:showmarks_enable=0' \
    -c 'runtime! macros/less.vim' -

How can I fix this?

Best Answer

When I try with the following script things are normal:

#!/bin/sh
sed -e 's/\x1B\[[[:digit:]]\+m//g' | \
vim \
    -c 'let no_plugin_maps = 1' \
    -c 'set nolist nomod ft=man' \
    -c 'let g:showmarks_enable=0' \
    -c 'runtime! macros/less.vim' -

I'm not sure what role col plays in the sequence, but it is certainly messing up the spaces. Until somebody gives a better solution, this will be my fix.

Edit: so col was the problem because it "replaces white-space characters with tabs where possible". To fix this tell col to use spaces instead of tabs with the -x option. The final config is as follow (with credit to Gilles).

#!/bin/sh
sed -e 's/\x1B\[[[:digit:]]\+m//g' | col -bx | \
vim \
    -c 'let no_plugin_maps = 1' \
    -c 'set nolist nomod ft=man' \
    -c 'let g:showmarks_enable=0' \
    -c 'runtime! macros/less.vim' -
Related Question