Mathieu Westphal
Mathieu Westphal

Reputation: 2633

Match a pattern in vim, not in the beginning of line

I am trying to search a pattern in vim, but the pattern must not be in the beginning of line, aka the first non white space character of a line, for indentation purpose.

eg. :

    Should() not be found
    This() Should() be found

using /Should, both Should pattern are found. I've tried to use something like, "not start of line" , but it is not working : /[^^] *Should. I've made it work using this : /\w.* *Should, but it is clearly not ideal.

Upvotes: 5

Views: 1719

Answers (3)

rkemp
rkemp

Reputation: 278

This uses a negative match on the start of line, which aligs with the OP's problem the best:

/^@

Upvotes: 1

Birei
Birei

Reputation: 36262

Use \zs to set a start of a match after a non-blank character followed by blanks:

/\S\s*\zsShould

Upvotes: 9

Amadan
Amadan

Reputation: 198314

Using positive look-behind, asserting there is at least one non-space character somewhere before the match:

/\(\S.*\)\@<=Should

Upvotes: 6

Related Questions