Need to duplicate text in each line and add equal sign and prefix to it

可紊 提交于 2019-12-21 04:29:24

问题


This is my text:

xxx
yyy
zzz

I would like it to be this text instead:

xxx = C.xxx
yyy = C.yyy
zzz = C.zzz

Is this possible to do in Vim?


回答1:


You can also use the simpler form:

:%s/.*/& = C.&



回答2:


Type this:

:%s/\(.*\)/\1 = c.\1/g

Breakdown:

  • % - work on all lines
  • \(.*\) - capture all the characters in a group ("group 1")
  • s/PATTERN/REPLACEMENT/g - do a string substitution
  • \1 in the replace pattern - refer to the matched group



回答3:


Select the text, then press : and type

s/\(.*\)/\1 = C.\1/


来源:https://stackoverflow.com/questions/7098364/need-to-duplicate-text-in-each-line-and-add-equal-sign-and-prefix-to-it

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