Sounds like a macro to me. Google vim macros for tons of useful information. Basically
- In command mode type q followed by some other letter which will be the register in which we store the macro. For example 'qw'.
- Run the commands you want to store for future use. This can be anything including regex substitutions, movements, inserts, deletes, etc.
- When you are done hit q again. You now have stored your actions for future use. To rerun what you just did type @w (or whatever letter you used for the register to save the macro in).
There's a lot of power in macros. Sometimes you want to save macros between sessions. When I want to do that, you can paste the macro into a buffer by pasting the register you just saved to. For example, if you saved your macro to register w, type "wp to paste register w (note that's the double quote, not two single quotes). You'll see some funny characters for when you pressed escape or enter. There are more readable ways of writing these like and , but ^[ and ^M will work too.
You can now yank those lines into a register (I see someone just posted an answer with this but somewhat differently than I'd do it) by selecting the text in visual mode and then typing "wy. This yanks the selected text into register w. Now to run the register as a macro, type @w as before.
If it's something you use often it might be worth mapping the macro to a shortcut command in your .vimrc. For example, here's a few maps I have in my vimrc to help me easily open and save my .vimrc
" For modifying the .vimrc
nmap ,e :e $HOME/.vimrc<cr>
nmap ,s :write!<cr>:source $HOME/.vimrc<cr>
Now when I'm editing any file and discover a new macro I'd like to save I type ,e to open my .vimrc. I paste the macro in, prepend a map statement (there's different maps depending on which mode you're in, plenty of documentation to explain this if you're interested), and save the .vimrc with ,s which also sources the .vimrc so that my new mapped command is available in other files without restarting vim.