Wiki

by yszheda

View project onGitHub

Tip 77: Stake the Boundaries of a Match

Return to the top: <<Practical Vim>>

  • \zs: marks the start of a match
  • \ze: marks the end of a match

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h /\zs

Lookaround Expressions

  • Vim’s \zs and \ze items are conceptually similar to Perl’s lookaround assertions.
    • \zs is roughly equivalent to positive lookbehind
    • \ze is equivalent to positive lookahead.
  • Vim also supports the full matrix of negative/positive lookahead/lookbehind assertions, but the syntax differs from Perl.

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h perl-patterns

Example: Rewrite

/\v"\zs[^"]+\ze"<CR>

using Vim’s positive lookaround items

/\v"@<=[^"]+"@=