2

this question seems hard to search answers by google.

I executed:

man cp > cp.txt
vim cp.txt

there are many "^H" in the file, it maybe backspace, how to get rid of them?

thinker3
  • 12,771
  • 5
  • 30
  • 36

3 Answers3

7

Just like our grand parents with their typewriters, man uses "backspace" (^H) to to go over the previous character and type it again to obtain "bold" letters.

While you can get rid of those ^H with a simple :%s/<C-v><C-h>//g you will get many doubled characters:

"original
N^HNA^HAM^HME^HE

"result
NNAAMMEE

So you would need to include the character just before or just after the ^H:

:%s/<C-v><C-h>.//g

But why go through all that trouble when you can obtain a clean text file directly with:

$ man cp | col -b > cp.txt
romainl
  • 186,200
  • 21
  • 280
  • 313
1

Those special control characters are probably ANSI escape sequences, used to add styling and color to the text. Vim doesn't parse those by default, but the AnsiEsc plugin uses Vim's conceal and syntax highlighting features to draw the text as intended.

Ben
  • 8,725
  • 1
  • 30
  • 48
1

Vim ships with a Man page reader. Add the following to your ~/.vimrc:

runtime ftplugin/man.vim

Now you can do :Man cp to open a man page on cp.

See :h :Man for more help.

Peter Rincker
  • 43,539
  • 9
  • 74
  • 101