Gansaikhan Shur
Gansaikhan Shur

Reputation: 75

How to delete everything before a certain character in Vim?

I have a text such as

/path/delivery3/afA.csv:afA;0.000;12.015;Spreker-A;;<lang:English> Yes </lang:English> Niko. <lang:English> Yes </lang:English> Niko, gaan ons verder praat oor die #um leerbesigheid? [no-speech]

using

:%s/.*;//

gives me

English> Niko, gaan ons verder praat oor die #um leerbesigheid? [no-speech]

How do I find the first : and output

afA;0.000;12.015;Spreker-A;;<lang:English> Yes </lang:English> Niko. <lang:English> Yes </lang:English> Niko, gaan ons verder praat oor die #um leerbesigheid? [no-speech]

Upvotes: 0

Views: 889

Answers (2)

Kent
Kent

Reputation: 195229

If you want to apply this change on a single line:

df:

If you want to apply it on all lines in a buffer you can record a simple macro using the above normal mode commands or:

:%norm! df:

If you really want to do it using the :s command:

:%s/[^:]*://

Upvotes: 1

m_mlvx
m_mlvx

Reputation: 188

See "How to make regex matchers non-greedy?"

The Vim non-greedy version of * is \{-}

So instead of :%s/.*://, you should get the result you want with :%s/.\{-}://

Upvotes: 1

Related Questions