Easiest way to swap occurrences of two strings in Vim?

后端 未结 5 1752
逝去的感伤
逝去的感伤 2020-12-04 15:39

What is the easiest way to replace all occurrences of string_a with string_b while at the same time changing anything that was already string

5条回答
  •  佛祖请我去吃肉
    2020-12-04 16:15

    You can do it with a single command as shown in my code below:

    :%s/\<\(string_a\|string_b\)\>/\=strpart("string_bstring_a", 8 * ("string_b" == submatch(0)), 8)/g
    

提交回复
热议问题