Case preserving substitute in Vim

前端 未结 6 1925
無奈伤痛
無奈伤痛 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:42

    sure u can

    :s/\cbad/\= strpart(submatch(0), 0 ,1) == toupper(strpart(submatch(0), 0, 1)) ? "GOOD" : "good"/

    ps. i'm guessing keepcase.vim encapsulates some similar logic :)

提交回复
热议问题