Conditional replace in vim

后端 未结 5 655
渐次进展
渐次进展 2021-01-05 01:10

I\'d like do use vim search-and-replace to replace all \" with \' and vice-versa. Is there a way to achieve this in one step? I\'m thinking of something like this:

5条回答
  •  长发绾君心
    2021-01-05 01:29

    Probably the laziest/easiest way:

      :%s/'/__/g | %s/"/'/g | %s/__/"/g
    

    Three basic steps combined into one line:

    1. convert ' to __ (or something random)
    2. convert " to '
    3. convert __ to "

    Then combine them with the | symbol.

    I'm sure some vim wizards will have a better solution, but that worked for me.

提交回复
热议问题