convert a string in upper case in vi

918 views Asked by At

I want to upper case words in vi (this is a verilog syntax file where I want to change the connectivity).

For example:

.STRING0(string1) .String2(string3),

I want to upper case one whole string and just first letter of second string something like

.STRING0(STRING1) .String2(String3),

My search pattern is:

%s/\.\(.*\)(\(.*\)) \.\(.*\)(\(.*\))/

and I need a replace pattern like

.\1(\2) .\3(\4)/

where buffer \2 is completely upper-cased and contents of buffer \4 is titled-cased. How is this possible?

1

There are 1 answers

0
Anthony Geoghegan On BEST ANSWER

Use the \U and \u substitution modifiers:

.\1(\U\2\E) .\3(\u\4)/

From the Vim help:

`\u`      next character made uppercase
`\U`      following characters made uppercase, until `\E`
`\E`      end of \u, \U, \l and \L

Note that the above substitution will use title case for the \4 match as long as it only contains one word, i.e., the substitution only converts the first character in the \4 match.