> -----Original Message----- > From: Meino Christian Cramer [mailto:[EMAIL PROTECTED] > Sent: Tuesday, August 08, 2006 6:27 AM > To: vim@vim.org > Subject: Saveing of a recorded macro > > Hi, > > is it possible and > > if "true" > then > how() > > endif > > to save a recorded macro to a file ?
I have done this in the past as follows: 1. Record your macro into the "a" register 2. Open your vimrc 3. Create a new line with: autocmd FileType sql let @a=' 4. Pressing (in insert mode) <C-R>a, this will paste your recorded macro into your vimrc, then add a final single quote. 5. The problem with step 4 is newlines and escapes are lost. So to fix this, you can: - For each newline (or carriage return you want in your macro) erase the new line and then (still in insert mode) press <C-V><C-M> (that is control V followed by control M). - For each escape you need in your macro, add a <C-V><C-[> 6. So you will end up with something like this: autocmd FileType sql let @a='/sys^Mcwbob^[nn.^M' This means, each time I edit a file with a filetype of sql, the "a" register will automatically have your macro recorded, so you can re-execute the macro (in normal mode) pressing @a. 7. This macro does: autocmd FileType sql let @a='/sys^Mcwbob^[nn.^M' - /sys^M - find sys (and the user had to have pressed enter) - cwbob^[ - change word to "bob" and press escape to get out of insert mode - Skip one find - .^M - repeat my last cw command 8. Obviously you are going to make lots of mistakes as you do this. It is very easy to test you macro, fix it, and test again. - You can move your cursor to after the first single quote. - Press v (to start linewise visual mode) - Move your cursor to the end of your macro - Press "ay - which yanks your visually selected text into the "a" register - Re-execute the macro pressing @a Hope that helps you. It is a bit figity, but it works and does what you need. Other people may have suggestions on how to replace the newline (or carriage returns) with the ^M and add the escapes where necessary. Dave