I have about 30 yaml files used as configs but the properties in the files are still under development. So there will be times when new properties have to be added.
It would be tedious to add the same property to all the different files, is there a quick way/tool?
There are a few ways, but my favorite would be to use :cdo
/:cfdo
. Simply :grep
/:vimgrep
your files then run a command with :cdo
.
:vimgrep /pattern/ *.yaml
:cdo s/foo/bar/|w
The command to :cdo
doesn't need to be a substitution, you can use any ex command (See :h ex-cmd-index
). For example use :normal
to capitalize the first character of each match, :cdo norm ~
.
See the following Vimcasts episode:
:cdo
is available in Vim 8.You can also may be able to use the argument list and :argdo
.
:args *.yaml
:argdo s/foo/bar/|w
Related Vimcasts espidodes:
For more help see:
:h :cdo
:h :vimgrep
:h :s
:h quickfix
:h arglist
:h :argdo
:h :args
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With