Sounds like a macro to me. Google vim macros for tons of useful information. Basically
- In command mode, enter q and then another letter, which will be the register in which we save the macro. For example, "qw".
- Run the commands you want to keep for future use. It can be anything, including regular expressions, moves, inserts, deletes, etc.
- When you're done, press q again. Now you have saved your actions for future use. To repeat what you just wrote, type @w (or any other letter you used to register to save the macro).
Macros have a lot of energy. Sometimes you want to save macros between sessions. When I want to do this, you can paste the macro into the buffer by inserting the register that you just saved. For example, if you saved your macro to register w, enter "wp to insert the register w (note that the double quote is not two single quotes). You will see some funny characters when you hit the escape button or enter. Readable methods their spellings are similar, but [^ and ^ M will also work.
Now you can output these lines to the register (I see that someone just sent an answer with this, but in a slightly different way than I did), selecting the text in visual mode and then typing "wy". to register w. Now, to run the register as a macro, enter @w as before.
If this is often used, it might be worth matching the macro with the shortcut command in your .vimrc. For example, here are a few maps that 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 edit any file and open a new macro, I would like to save the type, e, to open my .vimrc. I insert a macro, add a map operator (there are different maps, depending on which mode you are in, a lot of documentation to explain this if you are interested), and save .vimrc with, s, which is also the source of .vimrc so that my new mapped command is available in other files without restarting vim.
source share