Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "apply" backspace characters within a text file (ideally in vim)

Tags:

text

vim

I have a log file with backspace characters in it (^H). I'm looking through the file in Vim and it can be quite hard to see what's going on.

Ideally I'd like to be able to "apply" all the ^H on a given line/range so that I can see the final result.

I'd much rather do this within Vim on a line-by-line basis, but a solution which converts the whole file is better than nothing.

like image 981
Draemon Avatar asked Aug 19 '09 09:08

Draemon


2 Answers

Turn on the 'paste' option (using :set paste), and then press dd i <CTRL-R> 1 <ESC> on each line that you want to apply the backspaces to. This also works if you delete multiple lines, or even the whole file.

The key here is that you are using <CTRL-R> 1 in insert mode to 'type out' the contents of register 1 (where your deleted lines just got put), and 'paste' option prevents Vim from using any mappings or abbreviations.

like image 115
too much php Avatar answered Oct 07 '22 01:10

too much php


I googled this while trying to remember the command I had used before to `apply' backspaces, and then I remembered it: col -b - here is the manpage. (It does a little more and comes from BSD or more exactly AT&T UNIX as the manpage says, so if you are on Linux you may need to install an additional package, on debian its in bsdmainutils.)

like image 41
nox Avatar answered Oct 07 '22 01:10

nox