Thanks to ctf0 from where i forked it.
- Run Macro when files are opened
- Run defined command in automaton with delay
- Bind key to automaton macro
- Run macro defined in automaton from quick pick list
- Pass arguments to commands
- Run command in loop.
- Executing snippets as part of a macro
- Added
onLoad
so that the defined macro run whenever vs code open or a new file is loaded. - If you need to run the extension only when opening certain file extension, it can be defined using
onFileExtension
. - If you need to run the same macro on different file, define it using a
regex
"onFileExtension":".md|.txt|.html",
With
onLoad
defined totrue
andonFileExtension
not defined or set to*
then macro will run on every new file that is opened in editor.
onFileExtension
not defined then quick pick will show list of automaton macros even if there are no active file in editor.
Automaton quick pick list will show only those macros which are not present inautomaton.qp-ignore
list.
Create your own custom macros by adding them to your settings.json
(Code|File > Preferences > User Settings)
For example:
//
"automaton.list": {
"commentDown": {
"description" : "Copy line down and comment",
"action" :[
"editor.action.copyLinesDownAction",
"cursorUp",
"editor.action.addCommentLine",
"cursorDown"
]
},
"markdownShowPreview": {
"description" : "Default markdown preview on load",
"onLoad": true,
"onFileExtension":".md",
"action" :[
{
"command": "$delay",
"args": {
"delay": 1000
}
},
"markdown.showPreviewToSide"
]
}
}
//
First macro creates a copy of the current line, comments out the original line, and moves the cursor down to the copy, by invoking command automaton.commentDown
or pressing ctrl+shift+p
and Automaton: Execute
and select your defined macro from pick list.
Second macro is to view the markdown in preview mode everytime mardown file is open.
Add on load macro to automaton.qp-ignore
list so that on load macros don't bloat up pick list.
Your macros can run any built-in VS Code action, and even actions from other extensions.
To see all the names of possible actions VS Code can run, see Default Keyboard Shortcuts
(Code|File > Preferences > Keyboard Shortcuts)
Add description
to your macros that briefly describe what they do.
in keybindings.json
(Code|File > Preferences > Keyboard Shortcuts) add bindings to your macros:
{
"key": "ctrl+cmd+/",
"command": "automaton.commentDown"
}
Notice that automaton.my_macro_name
has to match what you named your macro.
Many commands accept arguments, like the "type" command which lets you insert text into the editor. For these cases use an object instead of a string when specifying the command to call in your settings.json
:
"automaton.list": {
"addSemicolon": {
"action":[
"cursorEnd",
{"command": "type", "args": {"text": ";" }}
]
}
}
Macros can also execute any of your snippets which is super neat. Just insert the same text that you would normally type for the snippet, followed by the insertSnippet
command:
"automaton.list": {
"doMySnippet": {
"action":[
{"command": "type", "args": {"text": "mySnippetPrefixHere" }},
"insertSnippet"
]
}
}
simply use Ctrl+P
or Alt+P
depend on your os, and type Automaton: Execute
then chose the macro you want to execute.
"automaton.list": {
"createNewTabAndPaste": {
"action": [
"workbench.action.files.newUntitledFile",
{
"command": "$delay",
"args": {
"delay": 50
}
},
"editor.action.clipboardPasteAction"
]
}
}
"automaton.list": {
"undoCommentDown": {
"action": [
{
"command": "undo",
"args": {
"command": "commentDown"
}
}
]
}
}
"automaton.list": {
"commentDown10": {
"action": [
{
"command": "commentDown",
"args": {
"times": 10
}
}
]
}
}
"automaton.list": {
"delay-100": {
"action": [
{
"command": "$delay",
"args": {
"delay": 100
}
}
]
},
"some-other-cmnd": {
// ...
},
},
"automaton.qp-allow": [
"some-other-cmnd",
],
"automaton.qp-ignore": [
"delay-100",
],
- Markdown doesn't show up properly in preview with macros defined on opening markdown file.
If your macro involves opening file for markdown preview then add delay
"markdownShowPreview": {
"onLoad": true,
"onFileExtension":".md",
"action" :[
{
"command": "$delay",
"args": {
"delay": 1000
}
},
"markdown.showPreview",
]
}
I was looking for some extension which will provides some way to open markdown file in preview mode only unless i want to view source cause I am lazy to click preview :-D