Search code examples
windowsvim

gVIM Windows grouping and backreferencing - E486: Pattern not found


I try to substitute the text:

abc def ghi

and delete the third word:

For this I use:

.s:\(\w+ \w+\) \w+:\1/

following this tutorial: 4.5 Grouping and Backreferences

Unfortunately when I execute this command I get

E486: Pattern not found: \(\w+ \w+\) w+

Any idea what I'm doing wrong?


Solution

  • The Quantifier, +, Needs to be Escaped

    Your pattern is fine, it is just that you need to escape your quantifier, +.

    You had this:

    .s:\(\w+ \w+\) \w+:\1/
    

    Change it to this:

    .s:\(\w\+ \w\+\) \w\+:\1/
    

    When in doubt, look it up in Vim's help files.

    :help pattern /notice section 3 covers magic and section 5 covers quantifiers/

    Some people like using magic which reduce the amount of escaping. You might want to peruse this.