I am trying to use a regex to search/replace a pattern / substitution / in vim.

I have a Java file which is trying to check if a weather data variable is set and if it is do one thing, if not omit it from being processed into JSON format. I wrote a method in a different class ( called StumpJunk.isSet - works just like PHP isset by checking if null or empty)

The old way I was doing it was if (varName != null)

The new pattern I want it to be is if (StumpJunk.isset(varName))

I have tried multiple regex methods in VIM to no luck:

:%s/if (\(.*\)) != null)/(StumpJunk.isSet(\1))/g
:%s/if \(\(.*\)\) \!\= null\)/\(StumpJunk.isSet\(\1\)\)/g
:%s/if \v\((.*)\) \!\= null\)/(StumpJunk.isSet(\1))/g
:%s/if \v\((.*)\) \!\= null\)/(StumpJunk.isSet("\1")/g

Every time it comes back saying pattern not found:

Pattern not found: \vif\((.*) \!\= null\) 

1 Answer 1


You have a ) too many in the first pattern, and you lack if in the replacement:

:%s/if (\(.*\) != null)/if (StumpJunk.isSet(\1))/g   
  • or :%s/\vif \((.*) \!\= null\)/if (StumpJunk.isSet(\1))/g if you want to use very-magic regex mode. Commented Sep 7, 2017 at 14:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .