The way I'd do it in vim is to record a macro of doing it interactively by hand once, then play back that macro. I have space bound to @q to make playing back the macro in the q register easy (using the q register because q is also how you start and stop recording a macro.)