Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do escaped angle brackets do in a vim regex?

Tags:

regex

vim

In gvim: switching tabs with keyboard, Susam Pal gives an example usage of vim's helpgrep as:

:helpgrep \<next\ tab\>

My question is what exactly do the escaped angle brackets accomplish? How does this differ from :helpgrep next\ tab or :helpgrep next tab?

like image 333
Jonathan Avatar asked Nov 25 '25 16:11

Jonathan


2 Answers

The special regular expression atoms \< and \> assert a (key)word boundary, what is frequently done with \b in other regular expression dialects.

Without it, next tab (no need to escape the space character BTW.) would also match inside nonext tabbing. As you often want to search for the whole word, not occurrences inside other words, this restricts the matches. (The * command does this for you, too.)

like image 55
Ingo Karkat Avatar answered Nov 28 '25 16:11

Ingo Karkat


Okay, so a quick :help regexp and /\\< brought me to the answer:

      ordinary atom ~
      magic   nomagic   matches ~
...

|/\<|   \<  \<  beginning of a word |/zero-width|
|/\>|   \>  \>  end of a word |/zero-width|

Hopefully this is useful for someone...

like image 35
Jonathan Avatar answered Nov 28 '25 15:11

Jonathan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!