Is there a way search backward from the cursor for a line that doesn't contain a pattern?
For example, many of my lines match the regular expression ^ adding: \i\+
. I want to find the first line above the current line which doesn't match this pattern, even if it is an empty line.
I don't want to use zero-width matching expressions because I don't want to have to specify a non-zero-width matching portion, which could cause the search to miss some qualifying lines.
I also avoided global commands, including the inverse global command :v
, because I want to search backward from the cursor to the first occurrence.
:help pattern
; maybe there's a negate-a-pattern syntax?\@!
and\@<!
looked promising, but I couldn't make them work (i.e., it's not as simple as\(pattern\)\@<!.
). Only other thing to add is that?pattern?-1
takes you to the line above a pattern match, so withhlsearch
turned on you could just holdn
until you're on an un-highlighted line. Or you could write a while loop to search backwards...