Vim replace two words with one another

十年热恋 提交于 2019-12-05 07:22:13

Aside from using a temporary word for the change, you could also use abolish plugin like this:

:%SubVert/{foo,bar}/{bar,foo}/g
kev

Take a look at this: how to write only one pattern to exchange two strings in two-ways in vim

:s/foo\|bar/\={'foo':'bar','bar':'foo'}[submatch(0)]/g
  1. :%s/foo/bbaarr/g
  2. :%s/bar/foo/g
  3. :%s/bbaarr/foo/g

It must exist an smartest way to do it, but this one will work for sure !

You can do it using temp word. Just be sure that it doesn't exists in the current document.

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