Jose Magana
Jose Magana

Reputation: 941

Add period into matched pattern in regex in vim

I'm trying to replace

underline{someword}

with

underline{someword.}

in Vim.

I've tried

:%s/underline{\w*}/underline{$1\.}/g

but it changes the matched patterns to

underline{$1.}

Why? How do I fix this?

Upvotes: 0

Views: 59

Answers (3)

Sato Katsura
Sato Katsura

Reputation: 3086

Use the ever-underappreciated \zs and \ze:

:%s/\munderline{\w*\zs\ze}/./g

Upvotes: 3

anubhava
anubhava

Reputation: 785856

You can use grouping:

:%s/\(underline{\w*\)}/\1\.}/g

Here \(...\) is used for grouping the match.

Upvotes: 3

d0nut
d0nut

Reputation: 2834

You forgot the capture group

:%s/underline{\(\w*\)}/underline{\1\.}/g

Upvotes: 3

Related Questions