Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim replacing linefeeds

Tags:

vim

I resisted Vim, but have now given in. It works large files like a hot knife through butter.

Situation: I have a large text file, I want to put a pipe character at the beginning and ending of each line.

Problem: These Vims and other variations didn't work:

:%s/$/|\$|
:%s/\r/|\r|
:%s/$/|\r|

I suspect it's something simple to fix this, but searching Google and Stack didn't help.

like image 259
Paulb Avatar asked Dec 20 '22 22:12

Paulb


1 Answers

You nearly had it:

:%s/^\|$/|/g

^\|$ means beginning or end of line. In a Vim regex, the | "or" pipe gets escaped. That is followed by /|/g -- replace with | globally.

like image 61
Michael Berkowski Avatar answered Jan 24 '23 06:01

Michael Berkowski