Update your npm packages with the help of Vim

I'm a big fan of yeoman for generating new projects for my web applications especially if I want to do a quick prototype. But there is one thing that bothers me. Nearly all generators are using old package dependencies which makes it really hard to find the proper documentation if you have to customize the build process.

There are many options to update the dependencies, here is a quick way to do it with the help of Vim:

alt

Open the package.json file in Vim and first of all go to the first line of the dependencies and start recording a macro using qq. Record the following macro:

  • f": find the first '"'
  • x: delete it
  • ;: find the next '"'
  • C: delete till the end of the line and enter insert mode
  • @latest: append the version indicator to the package name
  • ESC
  • J: join the next line with the current line

Stop recording the macro by pressing q and just run the macro 20 times by pressing 20@q. Copy the resulting line into the clipboard and use it with the following command (use :q! to exit Vim):

npm install --save-dev <paste packages here>

This is maybe not the best way to do this but it is a nice Vim exercise for sure.