Hello I have this text:

public static Type Name = new Type();
public static Type NameX() {}

If I search:

/public static \(.\{-}\) \(\w\+\)(

I get both lines selected until the (, but I expect the first one should not be.

I don't understand what I'm doing wrong, I thought that searching for \w means alphanumeric not including = or spaces, but when I add the (, it's like the \w\+ converts to .*

gVim version 9.0 patches 1-1778 on Windows 10

search and selected text

1 Answer 1


I would do:

/public static \(\S\+\) \(\w\+\)(

or maybe more readable using super magic:

/\vpublic static (\S+) (\w+)\(

What I believe happen on your test is that .\{-} is eating all the symbols you don't want (i.e: =, ).

Before you enter the parenthesis it does not because of its non-greedy nature (\{-}). It doesn't have to eat to find the next space. But has soon as you add the ( it has too to match and so it does.

You can analyse that by converting your search into a substituion:

:s/public static \(.\{-}\) \(\w\+\)(/1:\1, 2:\2/
  • Or even … ([^=]+) (\w+)\(
    – D. Ben Knoble
    Commented Sep 6, 2023 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.