开发者

how to write only one pattern to exchange two strings in two-ways in vim

开发者 https://www.devze.com 2023-03-10 04:39 出处:网络
xxx <=> zzz Original text: xxxyyyzzz Run command: :s/???/???/ It becomes: zzzyyyxxx Run t开发者_高级运维he same command above:

xxx <=> zzz


Original text:

xxxyyyzzz

Run command:

:s/???/???/

It becomes:

zzzyyyxxx

Run t开发者_高级运维he same command above:

:s/???/???/

Back to the original text:

xxxyyyzzz


just like toggle case(~)

aBCdeFg <=> AbcDEfG


Take a look at this: Can I substitute multiple items in a single regular expression in VIM or Perl?


Try this:

:s/(...)(yyy)(...)/\3\2\1/


You could always write your own macro. I'm assuming a macro for this specific example would not be helpful to you, but I could post one if you want.

0

精彩评论

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