Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim find and replace everything after '=' until end of line ($)

Tags:

regex

vim

I have a line of strings (10 to 20):

title = models.CharField(max_length=250)
...
field20 = models.DateField()

How can I use Vim's find and replace to remove everything from the equal sign until the end of line, so the text turns into:

title
...
field20

I'm familiar with the visual select find and replace (:s/\%Vfoo/bar/g), so I'd like to do something like (:s/\%V< = until $>//g), but this is what I am unsure how to find in Vim:

 = until $

I looked at the vimregex wiki, and tried the following with no success:

:s/\%V = (.*?)$//g
like image 365
Scott Skiles Avatar asked Dec 06 '22 11:12

Scott Skiles


1 Answers

Are you looking for this:

:%s/=.*/

?

It's the same as

:%s/=.*//

but the ending / can be omitted. You don't need the g btw because the pattern to the end of the line can match just once.

If you also want to remove the whitespace before the = use:

:%s/[[:blank:]]*=.*/

Note: If you think [[:blank:]] is hard to type, you can use \s instead. Both stand for space or tab.

like image 110
hek2mgl Avatar answered Dec 28 '22 05:12

hek2mgl