当前位置: 动力学知识库 > 问答 > 编程问答 >

regex - convert a string in upper case in vi

问题描述:

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?

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: