friddle
friddle

Reputation: 1347

VIM does not replace the word after the dot punctuation. How to change it?

I have the following problem

This is text:

printf("sysname %s",ut.sysname);

I want to use vim to replace sysname line by line. I type the command in my gvim:

:s/sysname/version

I want to get the output like this:

printf("version %s",ut.version);

But I get the output like this:

printf("version %s",ut.sysname);

What am I doing wrong?

Upvotes: 1

Views: 289

Answers (2)

CornSmith
CornSmith

Reputation: 2037

To do it on one line

:s/sysname/version/g

You can also use the qq macro recorder before typing that in, and press q after, and then use @q to replay that on any other lines you want to replace that on. Or press : up to select old commands.

Or to do it on every single line:

:%s/sysname/version/g

However with replacing every line you should be careful. If there is a lot of text try making your replacements more specific.

I would do

:%s/\(printf("\)sysname\(.*\)sysname/\1version\2version

Upvotes: 0

zmo
zmo

Reputation: 24802

you're missing the g command that applies to all matches on current line, instead of only the first one:

:s/sysname/version/g

as a bonus:

:%s/sysname/version/g

will replace all occurences in current file, not only on the current line.

Upvotes: 6

Related Questions