3

I have following text

_printer
_printer
_printer
_printer
_printer
_printer
_printer
_printer
printer

and I want to find the last one by using a search for the text printer which is not preceded by an underscore character _.

I know that zero matches are !: http://vimdoc.sourceforge.net/htmldoc/pattern.html#/zero-width

so I tried:

/!_printer
/!/_printer
/!\_printer
/![_]printer
/(_)@!printer
/_@!printer
//_@!printer
/\_@!printer

None of them works. What is the correct pattern for this search?

1 Answer 1

6

You're using the wrong zero width multi item. \@! is negative look-ahead. You could use it to e.g. find any printer that is not followed by an underscore:

/printer_\@!

The multi item you want to use is negative look-behind \_@<!:

/_\@<!printer

See :help \_@<!

An alternative technique would be to use:

/\_[^_]printer/s+1

Find any character (including an end-of-line) that is not an underscore, followed by printer, and place the cursor one character on from the beginning of the match.

1
  • And I believe one could use /\_[^_]\zsprinter as an alternative to the /s+1 form.
    – B Layer
    Commented Feb 7, 2018 at 5:00

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.