tags:

views:

61

answers:

2

Content:

1.                  Text is here.
20.                 More text.

Why does this Vim search and replace string fail?

:%s/^\d+\.\s+/# /g
+5  A: 

Some metacharacters need to be escaped in order to take effect:

:%s/^\d\+\.\s\+/# /g
Ignacio Vazquez-Abrams
I'll add to what has been said correctly. Most of the times it doesnt hurt to escape something metacharacters here and there when things doesnt work the first time. Even though the underlying concepts are the same, the implementation differs from engine to engine. Example ? `\s+` works in grep but vim demands `\s\+`
jeffjose
I have lost count of the number of times I have been bitten by this when switching between vim, grep, awk, python, sed etc.
Dave Kirby
+1  A: 

The + must be escaped in Vim's version of regex. So use \+.

Brian Rasmussen