PracticalVim Tip76 - yszheda/wiki GitHub Wiki

Table of Contents

Tip 76: Stake the Boundaries of a Word

Return to the top: <>

  • `/\v<{word}>`
  • We can approximate the meaning of `<` and `>` by combining the `\w` and `\W` character classes with the `\zs` and `\ze` match delimiters.
* `<`: `\W\zs\w` * `>`: `\w\ze\W` * `\w` matches word characters, including letters, numbers, and the "_" symbol * `\W` matches everything except for word characters.
  • In a very magic search, the naked < and > characters are interpreted as word delimiters, but in magic, nomagic, and very nomagic searches we have to escape them.

References:

  • word delimiters are used automatically each time we trigger the `*` or `#` commands.

References:

  • `g*` and `g#` perform the same searches without word delimiters.

Use Parentheses Without Capturing Their Contents

Example:

replace all occurrences of FIRSTNAME LASTNAME with LASTNAME, FIRSTNAME

⚠️ **GitHub.com Fallback** ⚠️