Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: select until first match

Tags:

vim

Lorem ipsum dolor sit amet, hello consectetur adipiscing elit. Vivamus lorem mauris, dictum in ornare sit amet, vulputate at nibh. Integer volutpat justo vitae enim ultrices ultrices. In quis tortor id diam tincidunt feugiat at ut odio. Donec faucibus sapien vitae ante aliquam malesuada. Nam facilisis, metus in tincidunt posuere, hello massa nisi vulputate nunc, id rutrum mi enim non risus. Phasellus ac nisl non tortor pulvinar accumsan at eget leo. Nunc neque mauris, vehicula eget malesuada a, vestibulum non urna. Proin iaculis sem vel nulla porta tristique. Donec magna diam, eleifend quis vehicula in, aliquam in dolor. In et tellus nec metus volutpat dapibus. Duis hello purus dolor, aliquet in vehicula id, adipiscing id lorem. Vivamus elementum, mauris non vulputate tempus, risus elit tincidunt nunc, et posuere velit ligula sit amet purus. Integer pellentesque ultrices sodales. Donec in arcu eu est ullamcorper tincidunt placerat at sem.

I want select everything from the beginning until first occur of hello

I try this

/^.*hello

But it returns whole text until the last hello.

So how to do it?

like image 923
Stenly.k Avatar asked Sep 02 '10 09:09

Stenly.k


2 Answers

You can use the visual mode and then search for hello to extend it

0v/hello<cr>

should do it

Otherwise to do a "non-greedy" search you can try {-}

/^.\{-\}hello
like image 107
mb14 Avatar answered Oct 22 '22 16:10

mb14


Just make the capture non-greedy:

/^.\{-}hello

This matches "as few as possible".

like image 45
polemon Avatar answered Oct 22 '22 15:10

polemon