1

I have several files where I want to change a word in several files from oldWord to newWord.

Please note I want to do this with the new cpo feature. I also would like to do this in one command line chain, rather than one command at a time.

Should this command do it? Or is there a better way do this in VIM?

:set hidden | :vimgrep oldWord ./gulp-tasks/*.s | :cdo s/oldWord/newWord/g | :set wall  ?
statox
  • 49,782
  • 19
  • 148
  • 225
dman
  • 143
  • 6
  • That answer is outdated, there is a way to do this with the new quick fix window and cpo command. Also, I want to do this with chained commands in one line rather than one at a time. – dman Dec 13 '17 at 17:54
  • 2
    that answer is not out of date. The first answer provides an :argdo/:bufdo method, the second :cdo method, and the 3rd uses the tried and true unix shell method. All of which are valid have there own pro's and con's. I am not aware of a :cpo command. I imagine you are looking for :cdo / :cfdo. See :h cdo. – Peter Rincker Dec 13 '17 at 17:59

1 Answers1

3

I imagine you meant something like this

:set hidden
:vimgrep /foo/ dir/*.s
:cfdo %s/foo/bar/g | w

All in one line:

:set hidden | vimgrep/foo/ dir/*.s | cfdo %s/foo/bar/g | w

Related Vimcasts episode: Project-wide find and replace

For more help see:

:h :vimgrep
:h :cfdo
:h 'hidden'
Peter Rincker
  • 15,854
  • 1
  • 36
  • 45