Does anyone know how to properly save/reuse macros recorded inside of a vim editor?
Does anyone know how to properly save/reuse macros recorded inside of a vim editor?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
qfollowed by a letter (for example ‘x’) to record a macro, then pressqto end the macro definition. The pattern surrounded by the starting and ending'q'during this definition just goes into one of the copy/paste registers (in this case, register ‘x’) so you can paste it with the"xpor"xPcommands in normal mode, where x is the register to paste. Typing"xpin normal mode inserts the contents in register x and exits back to normal mode.To save it, you open up .vimrc and paste the contents while defining the macro using
let @x, then the register will be around the next time you start vim.The format is something like:
Be careful of quotes, though. They would have to be escaped properly.
So to save a macro
'x', you can do:qxqlet @x = '...'(see the following)...pattern, you can use"xpjust at the place where the pattern should be placed. But this is not essential, you can just type in the macro definition.