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
\zsand\zeitems are conceptually similar to Perl’s lookaround assertions.-
\zsis roughly equivalent to positive lookbehind -
\zeis 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"@<=[^"]+"@=