Interactive search and replace from shell

前端 未结 8 1882
故里飘歌
故里飘歌 2020-12-29 12:32

Search and replace over multiple files is difficult in my editor. There are plenty of tricks that can be done with find, xargs and sed

8条回答
  •  孤独总比滥情好
    2020-12-29 13:03

    I would add these modifications to Dillon's answer:

    The -le option should be added to the grep command.

    vim `find . -name '*.c' -exec grep -le '\'  {} \;`
    

    Then you are in Vim, but you don't have the opportunity to choose what to replace, add c option at the end for interactive replacements and bufdo at the beginning for walking through every file:

    :bufdo %s/junk/rubbish/gce
    

    Later you save all your work:

    :bufdo wq!
    

提交回复
热议问题