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?
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?
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
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.
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.