ziulfer
ziulfer

Reputation: 1369

How to change all specified words in a file from upper to lower case at once in Vim?

I have a file in which I wrote many time the same word in upper case. I wanna modify all the words at once from upper to lower case, except those coming after a dot. Is that possible? I've found some tips here and there, but in all of them it is needed to place the cursor at the begging of the word.

Upvotes: 2

Views: 167

Answers (3)

Rupen B
Rupen B

Reputation: 76

:1,$s/\([^\.]\s\s*\)MYWORD/\1myword/g

This will replace all MYWORD with myword unless it follows a . and one or more spaces. This will not change MYWORD at the beginning of line. For those, you can run the following again:

:1,$s/^MYWORD/myword/

Upvotes: 1

shark555
shark555

Reputation: 2572

:%s/.*/\L&/g

Of course it must be proper regular expression. This one takes all(.*), the rest is up to you.

Details here: http://vim.wikia.com/wiki/Changing_case_with_regular_expressions

Upvotes: 3

jwodder
jwodder

Reputation: 57470

:%s/\.\@<!\<THEWORD\>/theword/g

Replace "THEWORD" and "theword" with the properly-cased equivalents of the actual word in question.

Upvotes: 5

Related Questions