Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim non-greedy search

Tags:

vim

I am trying to remove everything up to the first comma of each line in a csv file. The lines are like:

-29.45829963684082~149.14680480957031,-000029.45829963684082, 000149.14680480957031,WGS84
-29.46190071105957~149.09509277343750,-000029.46190071105957, 000149.09509277343750,WGS84

When I execute %s/.*,\\{-}// it removes everything!

If I use %s/.*,// it removes all except WGS84 which is what I would expect.

Can anyone tell me what I'm doing wrong? I thought \{-} imposed non-greedy matching in Vim.

Thanks,

John

like image 604
John M Avatar asked Jan 27 '26 23:01

John M


1 Answers

\{-} is the non-greedy matching in Vim, so you should use \{-} instead of *.

Try:

%s/.\{-},//
like image 188
xdazz Avatar answered Feb 03 '26 07:02

xdazz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!