Vim is sometimes also annoying. For instance I was oftentimes annoyed when I hit the q key followed by another key and ended up in macro recording mode. Before I learned that I could exit this mode by hitting q another time in comand mode, I was really frustrated. Thereafter it only got on my nerves. Until today I decided to find out what's so interesting about this record mode.
By hitting q you tell vim that you want to record a macro. If you hit a number or a letter thereafter, you tell vim into which register you want this macro to be stored. So hitting qq will end up recording a macro into register q. Now you can do anything you want with vim: insert text, search for things, open new files, ... When you are done, hit q for another time. Now the macro is recorded and you can re-run it using @
This feature came in handy today. I had to wrap a lot of one-liners with #ifdef X and #endif. So I recorded a macro that
- Entered insert mode.
- Opened a new line.
- Inserted #ifdef X
- Moved one line down.
- Opened another new line.
- Inserted #endif
- Exited insert mode.
Now can somebody tell me how I can store macros for reusing them later on?
No comments:
Post a Comment