Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a quick way to edit multiple yaml files at once? [closed]

Tags:

vim

yaml

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?

like image 618
dorachan2010 Avatar asked Sep 19 '25 20:09

dorachan2010


1 Answers

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:

  • Project-wide find and replace Note: :cdo is available in Vim 8.
  • Search multiple files with :vimgrep

You can also may be able to use the argument list and :argdo.

:args *.yaml
:argdo s/foo/bar/|w

Related Vimcasts espidodes:

  • Meet the arglist
  • Populating the arglist
  • Using :argdo to change multiple files

For more help see:

:h :cdo
:h :vimgrep
:h :s
:h quickfix
:h arglist
:h :argdo
:h :args
like image 113
Peter Rincker Avatar answered Sep 23 '25 12:09

Peter Rincker