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.
Related
A few days ago VSCode recently self-updated to version 1.75.0 and the functionality of runSelectedText seems to have changed.
Previously, as I recall, if this command was called, highlighted text would be run in terminal without the cursor moving. Now, if this command is run, the cursor jumps from the editor to the terminal. I would like to either (i) change a setting somewhere (if it exists) so that this command doesn't jump to the terminal, or, (ii) work out a way of returning the cursor to the editor (e.g., with a macro).
I previously had this as part of a macro to highlight the current line (using the macros extension). I selected the current line, ran the text in terminal, then cancelled the selection.
So my main approach so far has been a number of variations on the workbench.action.focusActiveEditorGroup command to include this within a macro.
As a MWE, the following macro I have included in settings.json:
"macros": {
"runAndReturn": [
"workbench.action.terminal.runSelectedText",
"workbench.action.focusActiveEditorGroup" // <--- this doesn't work/do anything
],
},
For me, when I run this macro, it executes the current line as expected, but the cursor moves to the terminal and doesn't return back to the editor.
This issue was reported here: https://github.com/microsoft/vscode/issues/173247
It was caused here https://github.com/microsoft/vscode/commit/305de596d216fb925e3cc298c0b67ad99ad0b6c2
It was fixed here: https://github.com/microsoft/vscode/pull/173573
See the first link for some workarounds people found, which you can use while waiting for a version with the fix to be released:
Using ctrl+1 to focus the first editor group (or the number of whichever editor group you want to focus).
Found by anderswe: Using the multi-command extension with the following:
{
"key": "cmd+enter", // or ctrl+enter
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.terminal.runSelectedText", // run line
"workbench.action.focusActiveEditorGroup", // shift focus back to editor
"cursorDown" // jump to next line so you can spam cmd+enter
]
},
"when": "editorTextFocus"
}
You can use ctrl+j to toggle the visibility of the integrated terminal view.
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.
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
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"
},
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.