开发者

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

开发者 https://www.devze.com 2023-03-29 07:41 出处:网络
This is my text: xxx yyy zzz I would like it to be this text instead: xxx = C.xxx yyy = C.yy开发者_JS百科y

This is my text:

xxx
yyy
zzz

I would like it to be this text instead:

xxx = C.xxx
yyy = C.yy开发者_JS百科y
zzz = C.zzz

Is this possible to do in Vim?


You can also use the simpler form:

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


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


Select the text, then press : and type

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

精彩评论

暂无评论...
验证码 换一张
取 消