Conditional replace in vim

后端 未结 5 670
渐次进展
渐次进展 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:35

    Another approach (that's more suited to scripting) is to use the built-in tr() function. To apply it on the buffer, getline() / setline() is used:

    :call setline('.', tr(getline('.'), "'\"", "\"'"))
    

提交回复
热议问题