3

For example:

I have several lines starting with :q:, which I want to jump to:

:q: regex syntax
(...)
:q: regex examples
(...)

Now I want to jump to the start of regex syntax or regex example with a specific regex find expression via /. Is this possible?

Why not just use W to jump to it? Well, it would just be nice to jump to each expression with the use of n and N.

5

You can use \zs (and it's complement, \ze), e.g.

/:q: \zs

should work for your example (assuming there is exactly 1 space after the second :)

It works by setting the start (or end in the case of \ze) of the matching text to a point somewhere in the middle of the regex. Check out :h \zs, it has a much better description than I can give, with additional examples.

| improve this answer | |
  • Haha, I have written a whole custom command and mapped it in the meantime, but this works so much better, thank you! – hgiesel Apr 18 '18 at 21:33
3

You can change the location in which the cursor is left after a search by using an offset:

You can either an "end" or "start" offset for your specific example:

/:q:/e+2
/:q:/s+4

See :help search-offset for more details.

You can apply these offsets retroactively to an existing search by using an empty regular expression:

/:q:
//e+2
| improve this answer | |
  • +1, this is a better solution than mine if, as in this case, the offset is a fixed number of characters. – flemingfleming May 1 '18 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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