VSCode macros extension wrong sequence - visual-studio-code

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

Related

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.

Sublime fails to open new_file in macro

In Sublime (Version 3.2.2, Build 3211) (Ubuntu 18.04.5), I'd like to record a macro where I select-all, copy and paste the current content into another, unsaved file. And then do other commands as well, but I'm not even getting that far. The new-file step doesn't seem to work – neither new, nor new_window, newWindow, new_file, newFile seem to work; not even reopen_last_file. It should be new_file, though.
The console throws this:
Unknown macro command new_file
Which is weird. The command new_file works fine in other contexts: looking at the key-bindings settings, ctrl+n is bound to the same command and the hotkey has no issues.
Selecting all, copying – even this following bit works as intended:
{
"command": "insert",
"args": {"characters": "Hello, Friend!\n"}
}
In their forums, user "jps" writes:
With regards to the other console messages (unknown command, etc), don’t worry about them, they’re supposed to be there :slight_smile:
… but this doesn't seem to be right if it's obviously not working.
I have a project open but closing the project has no effect.
Is there maybe a package or something missing?
Macros in sublime can only capture and replay TextCommand commands; that is, commands that directly modify the content of a buffer or it's visual state. Examples including adding or removing text, changing the selection, moving the cursor around or changing view specific settings (like toggling word wrap or changing rulers, etc).
Commands like new_file, new_window or opening and closing projects are WindowCommand commands, which can't be captured via a macro.
In order to run a sequence of commands that includes a WindowCommand (or ApplicationCommand), you need to use a package. Two examples of that which are readily available on Package Control are Chain of Command and Multicommand.

VS Code: "go to next problem" in current file rather than in any file?

I starting to use VS Code with Purescript and Haskell. The VS Code function "Go to next problem" is very handy, except that it goes to any problem (including warnings) in any file. I would like it to go to the next problem in this file.
Alternatively, is there a way to see warnings or errors without needing to use the mouse to hover over them? "Go to next problem" does that with a peek window, but otherwise it's annoying to have to take my hands off the keyboard.
I'm using Code Insiders.
In Code you can use: (type in ctrl + shift + p console)
Go to next problem(Error, Warning, Info).
This loops over the errors in current file, never changes file.
When you run f8, this starts other command
Go to next problem in Files (Error, Warning, Info)
Just add some shortcut to first one
Alt+F8 is difficult for me so I use a custom binding. The command name is the rather cryptic
editor.action.marker.next
mine is assigned like so:
{
"key": "ctrl+numpad1",
"command": "editor.action.marker.next",
"when": "editorFocus"
},

Create new untitled file and set language mode

I have this macro
"macros": {
"newScratchFile": [
"workbench.action.files.newUntitledFile",
"workbench.action.editor.changeLanguageMode"
]
},
Which used to work great with this extension but it appears Microsoft broke it as some point in time.
Now when I activate it, I do get a new untitled file, and the language mode popup opens for a split second but then disappears before I get a chance to type anything.
Is there a way to fix my macro so the language picker remains open?
I'm sorry to say it is probably the macro extension. That extension has been "quiet" for awhile and the two PR's are pretty important (see the issues) and haven't been incorporated. So the extension has been forked. I was a big fan of the original macros extension but now I use multi-command which works better.
I tried your commands in multi-command and it works flawlessly.
{
"command": "multiCommand.newFileAndMode",
// "interval": 250,
"sequence": [
"workbench.action.files.newUntitledFile",
"workbench.action.editor.changeLanguageMode"
]
}
It also has support for an interval time between execution of the commands which occasionally comes in handy. See, e.g., vscode terminal: terminate process without prompt my answer there to terminating a process and answering Y and enter in one keychord from a texteditor or terminal which wouldn't work without the delay - for the process to terminate.

Is it possible to auto-indent only the current line on Visual Studio Code?

On Atom (and many other editors), there is the auto-indent command which allows us to auto-indent the line the cursor is on. Is there an equivalent in Visual Studio Code ?
I know there is the formatter action on Visual Studio Code but from what i have seen, it can be used only to :
format a selection (ctrl-K ctrl-F)
format the hole document (ctrl + shift + I)
I would like to be able to format the line the cursor is on without reformating the whole document and without having to make a selection.
Basically, i would like to configure the [TAB] key so that when i press [TAB], it auto-indents only the line the cursor is on :
if there is nothing written on the line, it just put the cursor at the right place so that when i start writting, the code is correctly indented.
if there is already something written on the line, it audo-indents the line
Is it possible ?
So I have skimmed through the source code and seems there is no setting currently available to make this happen. There is a lot of work happening in pipeline for indentation
https://github.com/Microsoft/vscode/issues/17868
VSCode use Monaco Editor under the hood
https://github.com/Microsoft/monaco-editor/issues/612
The current python configs are located in
https://github.com/Microsoft/vscode/tree/master/extensions/python
I tried, but understanding how all this integrates and works together just to fix one indent issue was just overwhelming. So I would just for the time being open a enhancement request with VScode and let the experts take a call and do the job
Allow me to humbly suggest that you are looking for the solution in the wrong place.
I would suggest the following setting:
"editor.formatOnType": true,
You have focused on "tab" doing the correct indentation. But with this setting you need not press the tab key at all. Just type the line with a normal return at the end. Visual Studio Code will then indent (and format) that line correctly.
If you install the extension emacs-tab, you can do this:
{
"key": "tab",
"command": "emacs-tab.reindentCurrentLine",
"when": "editorTextFocus"
}
Which, as far as I understand you, does exactly what you want (and doesn't format the line in other ways, such as breaking it if it is too long, and so on).
This extension worked for me, and allows typing Tab with the cursor mid-line to get proper indentation similar to what I was used to on Emacs.
Note that it basically does the same as the extension recommended in this answer but at the time of this writing that extension appears to be unmaintained and has some open issues.