Pavel K.
Pavel K.

Reputation: 6817

non-greedy multiline search in vim

I am trying to search ruby file and find all methods (before autoreplacing them later). In vim, i use following regexp:

/\vdef.*(\n.*){-}end

However even though i use "{-}", it selects whole file's contents.

Upvotes: 16

Views: 3897

Answers (3)

user2161673
user2161673

Reputation: 91

In my version of Vim, you need to escape the {, as well as using \_. as other answers have said:

/def\_.\{-}end

Upvotes: 9

jkshah
jkshah

Reputation: 11703

Try following regex.

/\vdef(\n|.){-}end

.* was culprit in your case

Upvotes: 6

Birei
Birei

Reputation: 36262

uses \_. to include the newline character to the common ..

/\vdef\_.{-}end

Upvotes: 15

Related Questions