Every decent text editor has some sort of macros for automating repetitive tasks. Vim is no exception. Here is a short howto.