I always forget or make a mistake on how to make a macro in VI so today I noticed that I kept on messing up too much and this has gone on way to long:
- put the cursor where you want to start recording
- make sure your in command mode
- type the letter "q" then choose a letter between a-z or A-Z to assign the macro
- you should notice the "-recording-" message in the status bar
- do your actions that you want in the macro
- if you use the insert command make sure to use "esc" to get out of insert mode before ending the macro
- end the macro by pressing "q"
to use the macro:
- position the cursor where you want to use the macro
- type "@" then the letter you choose for your macro
to repeat the macro many times:
- position the cursor where you want the macro to repeat
- type a number
- type "@"
- then type the macro letter
here is an example of howto use the # symbol to comment out a line for 300 lines:
- type "q"
- type "a" (assigns the macro to this letter)
- type "i" (go to insert mode)
- type "#" (to insert the comment)
- type esc to get out of insert mode
- type "h" to move one character to the left
- type "j" to move one line down
- type "q" to end the macro
- type "300" then "@" then "a" to repeat the macro 300 times
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.