Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vim \zs and \ze #26

Open
OnlineCop opened this issue Feb 16, 2024 · 1 comment
Open

Vim \zs and \ze #26

OnlineCop opened this issue Feb 16, 2024 · 1 comment

Comments

@OnlineCop
Copy link

I apologize in advance; I am a very infrequent vim user, so some of this may need to be double-checked.

  • \zs sets the start of a match.
  • \ze sets the end of a match.

Vim's \zs appears to work like PCRE's \K (which discards matched text up to that point):

  • PCRE pattern: s/foo\Kfoo/bar/g
  • Vim pattern: :%s/foo\zsfoo/bar/g

Text: foofoofoofoo
Result: foobarfoobar

On the other hand, vim's \ze appears to work more like a lookahead:

  • PCRE pattern: s/foo(?=foo)/bar/g
  • Vim pattern: :%s/foo\zefoo/bar/g
  • Vim's lookahead pattern: :%s/foo\(foo\)\@=/bar/g

Text: foofoofoofoo
Result: barbarbarfoo

I thought it might be useful to include the \K similarities in your Vim cheatsheet.

@remram44
Copy link
Owner

This might be worth adding, though I don't know which other dialects have that feature. They also overlap somewhat with the look-around operators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants