我正在寻找一个允许我在两个单词之间交换的正则表达式。(其他 vim 快捷键也可以)
我有一个很长的清单:
a.transmit
b.receive
c.receive
d.transmit
我需要将传输的每个实例更改为接收,并将每个接收更改为传输,因此它应为:
a.receive
b.transmit
c.transmit
d.receive
谢谢,
您可以使用 Tim Pope 的Abolish插件轻松做到这一点
:%S/{transmit,receive}/{receive,transmit}
你可以这样做:
:%s/\v(transmit|receive)/\={'transmit':'receive','receive':'transmit'}[submatch(0)]/g
Yes, you can use an expression:
:%s/\(receive\|transmit\)/\=submatch(1) == 'receive' ? 'transmit' : 'receive'
It's pretty self-explanatory - if the matched group is receive
the expression evalutes to transmit
, otherwise to receive
.
不是一个命令,但如果你愿意使用 sed 3 次,你可以做一些类似的事情
:%s/transmit/temporaryholdervalue/g
:%s/receive/transmit/g
:%s/temporaryholdervalue/transmit/g
这应该切换所有值。