user956609
user956609

Reputation: 1311

Im using vim to check man page, and there is some weird character,how to make it normal?

I'm trying using

man ascii | vi -

to check ascii manual with vim,
then there are some weird character like '^H'

weird character in vim

how to make it normal?

EDIT:

i think this is due to some wrong config of my vim, or terminal, because i tried some other machine,and it works fine,any body help?

Upvotes: 7

Views: 1831

Answers (1)

filbranden
filbranden

Reputation: 8898

What you're seeing here is the man page convention for typesetting bold and underlined characters.

The ^H character is the "backspace" or BS character, which you can find in ascii(7) as ASCII 8.

Displaying as ^H is a convention to indicate "Control-H", the caret being a symbol for the "Control" key, since that's a key combination that generate this control character (note that "H" is the eighth letter, also it's on the same row as BS in the ASCII chart at the man page.)

Also note that ^H here is a single character and not the separate ^ and H characters. If you move along that line with l motion repeatedly, you'll see Vim skips the Hs. Vim might also display them in a different color to make it clear they're special characters.

The effect you're seeing here is called overstruck characters and it comes from the days when computers would be connected to line printers rather than screens. Man pages were created early in the Unix days and are typeset with a program named nroff (which has roots that predate even Unix) that uses these sequences to encode its text decorations, even to this day.

So one way to make text bold (or, print it stronger) was to print a letter, back out one space, then print it again. In your example, N^HNA^HAM^HME^HE is being used to print the word NAME in bold.

Typically, you'll use a man pager program that knows how to handle those sequences. For instance, less has specific support for overstruck text and is able to recognize those sequences using backspace (or carriage return, also possible to use it for that) and convert into bold or underline text using terminal escape sequences which actually achieve those effects in a terminal.

If you're using a different pager, often you'll use col -b to strip your text from those sequences. (See col(1) for details.) Note that col -b doesn't produce terminal escape sequences around overstruck text, it simply removes all overstriking, leaves the text plain, so any text reader can display it.

(In that sense, man ascii | col -b | vi - is one possible way around your issue, but not the best one.)

Vim doesn't support overstruck text or terminal escape sequences in text it receives as input. So the approach used to use Vim as a man pager is to strip all overstriking (same as col -b does) and then use Vim's syntax highlighting feature to mark man page sections etc. (So instead of seeing the original markings typeset into the man pages, those are all being stripped and you're actually seeing Vim syntax configuration for man pages.)

This is accomplished by the manpager.vim script, which is shipped by default with Vim and which registers a :MANPAGER command that you can access as vim +MANPAGER -.

You'll see that part of what that does is to remove overstriking, same as col -b does. It also sets the file type correctly and enables syntax highlighting, setting up Vim as a suitable viewer for man pages.

I think this is due to some wrong config of my vim, or terminal, because I tried it in some other machine and it works fine there.

I'd say this is most likely due to the man pages being typeset differently between the two systems.

Man pages themselves and the pipelines used to generate them from the source code are not very uniform and you'll find differences across operating systems or even Linux distributions.

It's possible that on your other system all man pages get stripped using col -b at creation time, or that man will strip them when piping them to something that's not what's set in $MANPAGER, or even that they don't have anything marked as bold or underline in their sources.

Hard to tell exactly which (your reference to working fine on another machine lacks details to tell), but this would be my bet.


In short: To use Vim as a pager for man pages, instead of piping them to Vim, set it up so that man will run vim as a pager itself.

In Vim, see :help manpager.vim which has instructions on how to set this up.

In short, all you need is to add this line to your ~/.bash_profile:

export MANPAGER="vim -M +MANPAGER -"

After setting that up and logging in again, all you need is:

$ man ascii

And man will launch vim in the right mode for you.

Upvotes: 14

Related Questions