Case preserving substitute in Vim

前端 未结 6 1890
無奈伤痛
無奈伤痛 2020-12-02 06:32

Can this can be done in Vim?

What I mean is: searching for \'BadJob\' and replacing with \'GoodJob\' would do the following replacements



        
6条回答
  •  醉梦人生
    2020-12-02 06:40

    If you're only matching an exact (case-independent) string with a few possible capitalizations, another possibility is:

    :s/abc/\={'abc':'xyz','Abc':'Xyz'}[submatch(0)]/i
    

提交回复
热议问题