How do I manipulate character case in search and replace in vim?

可紊 提交于 2019-12-24 02:52:40

问题


for example, I have:

  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;

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 

(and somehow capitialize the first character of \1)


回答1:


Use the \u prefix for the match in the replace clause:

For one at a time:

:%s/ double \(\w\+\)/ double \u\1/c

For all at once:

:%s/ double \(\w\+\)/ double \u\1/g

If you want to make the whole match uppercase use the \U and \E delimiters:

:%s/ double \(\w\+\)/ double \U\1\E/g



回答2:


Use \u

%s/ double \(\w\+\)/ double \u\1/c



回答3:


Couldn't get the other's to work, this works for me:

:%s/\(double \)\<\(\w\)\(\w*\)\>/\1\u\2\L\3/g



回答4:


s:\(\<double\>\)\(\<\w\+\>\):\1 \u\2:g

or sume-such.



来源:https://stackoverflow.com/questions/10745694/how-do-i-manipulate-character-case-in-search-and-replace-in-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!