Macros can be very helpful; they are saved with the .sublime-macro
extensions as a JSON-formatted file.
Before creating a new macro, we should understand what the use case is. If we find ourselves doing the same actions over and over again, we should use a macro for it. For example, when writing C# code, we always go to the end of the line to insert a semicolon and press Enter. How can we do this faster?
To record a macro, simply press Ctrl + Q on Windows or Linux and Control + Q on OS X. We will notice that the status bar says Starting to record macro…, as shown in the following screenshot:
Let's record the macro. Press Ctrl + right arrow + ; + Enter on Windows or Linux and Command + Right Arrow + ; + Return on OS X. Finally, press Ctrl + Q to stop recording.
To play the recorded macro, simply press Ctrl + Shift + Q on Windows or Linux and Control + Shift + Q on OS X. Sublime will always play the last recorded macro.
We can also save the recorded macro and edit it manually. Let's go to Tools | Save Macro… and save it under Packages/User/semicolon.sublime-macro
. When opened open it for editing, we should see the following:
[ { "args": { "to": "eol" }, "command": "move_to" }, { "args": { "characters": ";" }, "command": "insert" }, { "args": { "characters": " " }, "command": "insert" } ]
We can edit the macro to insert);
instead of ;
just by changing the value of "characters"
in the second row to ");"
.
For the full list of commands, visit http://docs.sublimetext.info/en/sublime-text-3/reference/commands.html.