I’m trying to know how vim experts use macro’s in vim for day-to-day coding – I have a lot of custom shortcuts/mappings that I use frequently , but haven’t come across any good ideas of macros.
It may have been a macro which you had used before , to simplify a task tremendously – I just need ideas as to how to productively use this feature in vim !
Macros are generally an “on the fly” automation tool. Lets say you have a list of items:
You can quickly write a macro to make them into an html list for example. Starting from the beginning of the word apple record the following macro:
i<li><Esc>A</li><Esc><CR>into register 1.The <CR> is key because it allows you to jump to the next line and thus use the “count” modifier on your macro execution which provides multiline macro execution
Then go to the beginning of orange and use 4@1 ([count]@[register letter]) to apply the macro to the rest of the entries to get this:
Imagine using that on a list of 200 items. Saves time no?
Of course this example is trivial and you could do this with a search and replace but you can imagine more complex examples…