You are not logged in.

#1 2021-11-02 12:04:36

amaro
Member
From: xfce
Registered: 2014-05-09
Posts: 367

[SOLVED] vim insert new line before specific characters

Hello everybody!

I am trying to insert new line in a file that looks like

C89 Ruy Lopez, Marshall, Herman Steiner variation1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Ba4 Nf6 5. O-O Be7 6. Re1 b5 7. Bb3 O-O 8. c3 d5 9. exd5 e4
C90-C99 Ruy Lopez, closed1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Ba4 Nf6 5. O-O Be7 6. Re1 b5 7. Bb3  O-O 8. c3 d6

I want to insert the new line before every '1.' characters.
After some goooooooooooogling I tried diff variations that did not work I finally realised I need to put '\' in front of the '.' to make it work

:1,$s/1\./\r1\./g

It worked but it also included a new line every time it found '11.' turning it into

1
1.

What is the right command that will not affect lines with '11.'?
Thank you in advance!

Last edited by amaro (2021-11-02 12:49:16)

Offline

#2 2021-11-02 12:28:22

lmn
Member
Registered: 2021-05-09
Posts: 93
Website

Re: [SOLVED] vim insert new line before specific characters

amaro wrote:

I want to insert the new line before every '1.' characters.

That's exactly what the command you have given does.

Do you want to specifically exclude 11. ? What about 21.?

This looks like some sort of bibliography and your trying to separate some enumeration from the beginning?
Assuming just ASCII for now you could try something with capture groups

%s/\(\a\)1./\1\r1./

Edit: or just remove the global if they are ordered and 11. does not come before 1.

Last edited by lmn (2021-11-02 12:29:40)

Offline

#3 2021-11-02 12:48:42

amaro
Member
From: xfce
Registered: 2014-05-09
Posts: 367

Re: [SOLVED] vim insert new line before specific characters

Thank you, lmn!

Yes, it's ordered. Removing the global did it. I overlooked it.
Your command worked too!

Offline

Board footer

Powered by FluxBB