如何在搜索中操作字符大小写并在 vim 中替换? [英] How do I manipulate character case in search and replace in vim?
本文介绍了如何在搜索中操作字符大小写并在 vim 中替换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我有:
double foo = 0.0;
double bar = 0.0;
并且我想编写某种搜索来查找每个变量并将其更改为:
and I want to write some sort of search to find each variable and change it to:
double Foo = 0.0;
double Bar = 0.0;
我不想一次做这些一个变量(例如:%s/foo/Foo/g),而是一次做,接近于
I dont want to do these one variable at a time (e.g. :%s/foo/Foo/g) but rather all at once, something close to
:%s/ double \(\w\+\)/ double \1/c
(并以某种方式将 \1 的第一个字符大写)
(and somehow capitialize the first character of \1)
推荐答案
在替换子句中使用 \u
前缀来匹配:
Use the \u
prefix for the match in the replace clause:
一次一个:
:%s/ double \(\w\+\)/ double \u\1/c
一次性全部:
:%s/ double \(\w\+\)/ double \u\1/g
如果要使整个匹配大写,请使用 \U
和 \E
分隔符:
If you want to make the whole match uppercase use the \U
and \E
delimiters:
:%s/ double \(\w\+\)/ double \U\1\E/g
这篇关于如何在搜索中操作字符大小写并在 vim 中替换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文