Sublime Text run a macro with key bindings - macros

How do you define key bindings to run recorded macros in Sublime Text 2? I can record a macro, but how do I run it on demand?

Assuming you already know how to create and save a macro I will only show how to define a key binding to run the saved macros.
I couldn't locate an answer on SO and Google, so I decided to post the answer here for anyone else who needs to do such functionality in the future.
This has been tested in Sublime 2, but most likely is the same sytax as in Sublime 3. The file location of the saved macro may be different depending on version and where you decided to save your macro file.
In Sublime 2 the macros default to the Sublime 2\Data\Packages\User\ directory and is where I will reference in my example.
Example:
{ "keys": ["alt+shift+o"], "command": "run_macro_file", "args": {"file": "Packages/User/output.sublime-macro"} }
This binding will execute the macro file specified using the alt+shift+o key combination.

Related

How can I set a hotkey to input a command in VS Code's terminal? [duplicate]

This question already has answers here:
Shortcut for running terminal command in VS code
(4 answers)
Closed 8 days ago.
Is it possible to set a VS Code hotkey to input a command in the terminal?
I need to input r to hot reload my flutter app. and it'll be easier if I can have a hotkey for that.
I can use ctrl+` to switch to terminal and input r myself, but I hope that there will be an easier way.
As #rioV8 hinted in the comments, you can do this with the workbench.action.terminal.sendSequence keybinding command.
For official documentation, see https://code.visualstudio.com/docs/terminal/advanced#_custom-sequence-keybindings.
Here's a template of what it might look like in your keybindings.json file:
{
"key": "", // TODO put something here
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "r" }
}
Note: If the keybinding you want to use is already in use, I believe you need to explicitly disable it. You search for existing keybindings in the keybindings UI and then delete/disable them there.
Here's a bit more excerpt from the above linked docs:
This feature supports variable substitution.
The sendSequence command only works with the \u0000 format for using characters via their character code (not \x00). Read more about these hex codes and terminal sequences in the following resources:
XTerm Control Sequences
List of C0 and C1 control codes

Make a specific VSCode output view visible?

In the VSCode "panel" there are the tabs "problems", "output", "terminal", debug console". Within the output tab is a drop-down menu containing many different output views, such as "Tasks", "Extensions", "Git", etc.
I would like to have it make a specific output view visible automatically. For example, when starting a debug session, VSCode may have made the "Adapter Output" view visible, but I'd like to hit a hotkey (or fully automate it) to switch to a different output view.
I'm not certain if this can be done through a task or if it would require an extension, but I cannot find any information on it. Presumably it's possible, though, since VSCode obviously switches panel tabs automatically, and it will make different output views visible depending on the situation.
In this specific case, I'm using the cortex-debug add-on, and SWO text output is sent to an output view during debug sessions. I'm interested in having that output view made visible automatically when I launch the debug session.
Thanks!
Changing the Output View
"So obviously, as you have already mentioned, the way most people switch output views is by opening the drop-down reading the list, until they see the output-view they are looking for, which they then select... Which is slow. Drop downs are counter-productive when attempting to Navigate your Editor quickly. For me, it is easy to see why you want an alternate method for selecting the output's view."
There's a Better way.
For starters your going to need to access, and create custom keybindings. The command hooks are their for you to switch to the outputs you want, but they haven't been added to the default commands yet, and they may not be added ever (which is why you are going to add them now). Below is a simple guide explaining how to make a keybinding in VSCode:
Note: This is part 1 of 2 parts
PART #1
Creating Keybindings
Each Keybinding Has 3 Essential Properties:
key: this describes the pressed keys.
command: Contains the actual command that is to be executed, a limited list can be found in the VSCode Docs. (Click here to see them)
when: This is the when-context, which sets conditional True or False clause which is evaluated upon execution of the command you wrote.
as a reference, this is one of my keybindings I use for disabling ESLint on specific lines where I intentionally break Es-Lints rules.
// ~/.config/Code/User/keybindings.json
// This allows me to pin and unpin editor tabs using the same exact keys
// It is the when clause that makes these keybindings I created possible.
// ctrl+shift+space (& then) ctrl+shift+space (again)
{
"key": "ctrl+shift+space ctrl+shift+space",
"command": "workbench.action.pinEditor",
"when": "!activeEditorIsPinned"
},
{
"key": "ctrl+shift+space ctrl+shift+space",
"command": "workbench.action.unpinEditor",
"when": "activeEditorIsPinned"
},
Note: Sometimes their is an args property.
Moving on...
Part #2
Creating the Keybinding that is Specific to what you want:
Okay so now that you know how, I will give you the clauses, which are slightly hard to locate at first (or at-least they were for me), but once I found them I now always know where to look:
If you drop open the Command-Palette via the [F1] KEY and type "Keyboard Shortcuts", two options for "Keyboard Shortcuts" will popup:
One of the options will read: "Default Keyboard Shortcuts"
The other will simply read: "Keyboard Shortcuts"
They will both open keybindings.json files, but they are two different files in two different locations. The DEFAULT keybindings.json file will be Read-only (its not writable), it is the default keybindings that come with VS-Code. The Default one is important because it contains the long list of commands that can be used when creating keybindings. It is currently the best resource for Keybinding commands anywhere.
The regular keybindings.json file will be empty if you never used it, and this is where you can define your keybindings. To start while focused on the keybindings.json file, hit [Ctrl+k] [Ctrl+k] (twice back to back). An input will pop up where you can define a keybinding, by pressing any keys you want. Once you have defined your keybinding press enter and it will create a preformatted keybinding block for you, it will pre-type the Key Combination you designed as well. In the block enter the When clause you want (you have to figure out when this keybinding is going to be executed, you may or may not be able to leave it blank. A blank "when": "" clause is like telling the editor...
_"This keybinding is to be executed at anytime I use the Key Combination that is associated with it via the key-property".
Last but not least the good stuff:
The output commands:
git.showOutput
notebook.diff.showOutputs
npm-script.showOutput
eslint.showOutputChannel
testing.openOutputPeek
testing.showMostRecentOutput
There may be more, but that's what I was able to find in the Default Keybindings.json file.

How can I write specific words on terminal( mainly GIT)?

When We press the uparrow button. it types "code.". can we write other words when we press some key? I want to write ./a.exe on the terminal when pressing some key. How can we do so in Visual studio code?
The integrated terminal inside the VS Code is very much customizable when it comes to key bindings. The official documentation says:
The workbench.action.terminal.sendSequence command can be used to send
a specific sequence of text to the terminal, including escape
sequences. This enables things like sending arrow keys, enter, cursor
moves, etc. The example below shows the sorts of things you can
achieve with this feature, it jumps over the word to the left of the
cursor (Ctrl+Left arrow) and presses backspace:
{
"key": "ctrl+u",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u001b[1;5D\u007f" }
}
This feature supports variable substitution.
Note that the command only works with the \u0000 format for using
characters via their character code (not \x00).

VS Code Change Language Using Keybinding

Is there a keybinding command string to change the language mode to a specific language?
I'd like to have a hotkey to change the language mode to JavaScript. For example, Ctrl + LCtrl + J:
{
"key": "ctrl+l ctrl+j",
"command": ???,
"args": ???
}
This GitHub issue "Expose 'change language' as command" makes me think that it has been implemented.
I often find myself researching VS Code keybindings and settings commands like this, and I haven't found reliable documentation for them. Please include your source when answering to help me out.
Update: I found this extension, vscode-change-language-mode. I'll try it out, but I'd still like to know if there's native support for it.
Related things that aren't answers to my question:
Change Language Mode shortcut Ctrl + KM command: "workbench.action.editor.changeLanguageMode".
Default Language setting: "files.defaultLanguage".
File Associations

VSCode macros extension wrong sequence

I'm currently trying to get a shortcut which opens the default and user keybindings in json side by side (pretty much the same what VSCode already provides for the settings.json). Since VSCode does not support that in itself, I tried to do it with the macros extension.
My code looks the following:
"macros": {
"openKeybindings": [
"workbench.action.openDefaultKeybindingsFile",
"workbench.action.openGlobalKeybindingsFile",
"workbench.action.moveEditorToNextGroup",
],
},
I can now trigger this macro with:
{ "key": "ctrl+alt+k", "command": "macros.openKeybindings" },
What I am thinking this macro should be executing is:
Open the default keybindins.json
Open the user keybindins.json
Move the user keybindins.json to a new editor window to the right so they are side by side
My problem now is, the macros does not seem to execute these three commands in sequence. What actually happens if I press ctrl+alt+k is that the default and user keybindings.json get opened in the new editor window to the right.
Can anyone explain to me why the macro does not execute the commands in order and maybe give me a solution to my problem?
Fixed that problem with this issue on the github of this macro