I'm tried each of the following keybindings.json ctrl+enter "command" settings to enable execution of two commands when the .py[thon] script editor extension is active. The single commands work but none of the attempts to associate multiple commands or a macros reference containing multiple commands, work. The later generates a "command 'macros.<macro defined in settings.json>' not found."
Any pointers on how I get multiple commands attached to a single keyboard shortcut definition, specifically what's wrong with how i'm setting up macros approach?
// %appdata%\Code\User\keybindings.json
[
{
"key": "ctrl+enter",
//"command": "python.execSelectionInTerminal",
//"command": "cursorDown",
//"command": [ "python.execSelectionInTerminal", "cursorDown" ],
//"command": "python.execSelectionInTerminal, cursorDown",
//"command": "python.execSelectionInTerminal && cursorDown",
"command": "macros.pythonExecuteLineAndMoveToNextOne",
"when": "editorTextFocus && editorLangId == 'python'"
}
]
// %appdata%\Code\User\settings.json
{
"macros": {
"pythonExecuteLineAndMoveToNextOne": [
"python.execSelectionInTerminal",
"cursorDown"
]
},
.
. .
. . .
}
Adding duplicate of answer raised in comments so it can be accepted to change state of this question to answered.
The fix was to add the #name:macros #publisher:geddski vscode extension which was mentioned in the article i used to arrive at the multi-step macro definitions. It wasn't initially clear that it was a requirement.
Related
I'm configuring keybindings of Visual Studio Code. For accepting suggestions, two keybindings are set by default, but I have no idea why there are acceptAlternativeSelectedSuggestion and acceptSelectedSuggestion as they seem to cause the same effect. So, what is the difference?
{
"key": "shift+tab",
"command": "acceptAlternativeSelectedSuggestion",
"when": "suggestWidgetHasFocusedSuggestion && suggestWidgetVisible && textInputFocus"
},
{
"key": "tab",
"command": "acceptSelectedSuggestion",
"when": "suggestWidgetHasFocusedSuggestion && suggestWidgetVisible && textInputFocus"
},
Experimentally, it affects what happens to the text to the right of the caret if the caret is in the middle of a word during completion.
acceptSelectedSuggestion causes the text to the right of the caret to be kept after the suggestion is accepted.
acceptAlternativeSelectedSuggestion causes the text to the right of the caret to be removed after the suggestion is accepted.
If you feel like further digging, the source code can be found in the following files:
src/vs/editor/contrib/suggest/browser/suggestController.ts
src/vs/editor/contrib/inlineCompletions/browser/suggestWidgetInlineCompletionProvider.ts
Is it possible to save Terminal settings to a workspace? For most of my projects I always have two terminal tabs open. One where I do all of my git work and one where I run gulp tasks. These are two different folders and neither are the project root. When I open a saved workspace it always just opens one tab to the project root.
Look at the Restore Terminals extension. For example, in your settings.json:
"restoreTerminals.runOnStartup": false, // true is the default
// set to false if using a keybinding or command palette
"restoreTerminals.terminals": [
{
"splitTerminals": [
{
"name": "git",
"commands": [
"cd <your directory>",
"npm run test" // your git command(s)
]
}
]
},
{
"splitTerminals": [
{
"name": "gulp",
"commands": [
"cd zip",
"gulp sass"
]
}
]
}
]
will open two terminals, one for your git work and one for the gulp work. They can each take multiple commands.
Example keybinding:
{
"key": "shift+alt+t", // whatever keybinding if you wish
"command": "restore-terminals.restoreTerminals",
},
or you can it run at start-up.
The Tasks feature is the current recommended way to handle this. There is no need for an extension. See Automating launching of terminals in the VS Code documentation.
Then make sure that tasks are run automatically when the folder is opened by running command Tasks: Manage Automatic Tasks in Folder and choosing Allow Automatic Tasks in Folder (see Run behavior).
Please also see the note here that:
Task support is only available when working on a workspace folder. It is not available when editing single files."
For a Linux not-so-officially-recommended way that works. The xdotool key emulator for linux can be used. I'm sure any Windows key emulator could be used to accomplish the same thing.
First, set the Terminal: Change Color to a keyboard shortcut. Here I'm using Ctrl+Shift+C. This is done by bringing up the command pallet (Cntrl+Shift+P) and, typing Terminal: Change Color
Here is my Restore Terminals json from VS Code settings. The lengthy cli command to update the colors needs to be activated on the last tab, as it is the tab that is focused when Restore Tabs is finished restoring tabs.
We need a bit of a timeout between the setting of each tab color, as VS Code takes just about a 10th of a second to complete the command. The built in keyboard shortcut cntrl+Page_Up is used to bring the previous tabs into focus. This script is for a WorkSpace that includes a Docker-Compose enviroment that contains 3 repos.
Be sure to save this in your Workspace settings, not your user settings. For more info, visit: https://code.visualstudio.com/docs/getstarted/settings
"restoreTerminals.terminals": [
{
"splitTerminals": [
{
"name": "docker-compose",
"commands": ["cd ..", "cd docker-compose", "clear"]
},
]
},
{
"splitTerminals": [
{
"name": "api",
"commands": ["cd ..", "cd api", "clear"]
},
]
},
{
"splitTerminals": [
{
"name": "ui",
"commands": [
"cd ..",
"cd ui",
"xdotool key ctrl+shift+c && xdotool type 'cyan' && xdotool key Return && sleep .2",
"xdotool key ctrl+Page_Up && xdotool key ctrl+shift+c && xdotool type 'green' && xdotool key Return && sleep .2",
"xdotool key ctrl+Page_Up && xdotool key ctrl+shift+c && xdotool type 'yellow' && xdotool key Return",
"clear"
]
},
]
}
],
And the end result... Is that all tab colors are updated after they are restored.
Of course, anyone who has ever used keyboard emulation for automating tasks should know you can not be entering text or clicking elsewhere until the task is complete.
If you're on windows you can use powershell to create a similar effect to #CodeBloodedChris's solution.
Create a powershell script in your workspace root directory (or where ever the last terminal's final path is) and name it something like 'restore-terminal-customization.ps1' or something like that. Then add the following code to it:
# Uses windows forms to send keystrokes to customize vscode Terminals
Add-Type -AssemblyName System.Windows.Forms
$tabDelay = .6
# Last Terminal
[System.Windows.Forms.SendKeys]::SendWait("^+cRed~")
# Second to last Terminal
[System.Windows.Forms.SendKeys]::SendWait("^{PGUP}"); Start-Sleep -s $tabDelay
[System.Windows.Forms.SendKeys]::SendWait("^+cYellow~")
# Third to last Terminal
[System.Windows.Forms.SendKeys]::SendWait("^{PGUP}"); Start-Sleep -s $tabDelay
[System.Windows.Forms.SendKeys]::SendWait("^+cMagenta~")
In this script the '^+c' is ctrl+shift+c and '~' is the enter key.
Similarly I had also set up a keybinding for the icons which uses ctrl+shift+i '^+i'. Here's an example of setting both the color and the icon of a terminal:
# Fourth to last Terminal
[System.Windows.Forms.SendKeys]::SendWait("^{PGUP}"); Start-Sleep -s $tabDelay
[System.Windows.Forms.SendKeys]::SendWait("^+cGreen~^+iorganization~")
In your restoreTerminal's config call the script you created as a command in the last terminal on your list.
"restoreTerminals.terminals": [
{
"splitTerminals": [
{
"name": "docker-compose",
"commands": ["cd ..", "cd docker-compose", "clear"]
},
]
},
{
"splitTerminals": [
{
"name": "api",
"commands": ["cd ..", "cd api", "clear"]
},
]
},
{
"splitTerminals": [
{
"name": "ui",
"commands": [
"cd ..",
"cd ui",
".\restore-terminal-customization.ps1",
"clear"
]
},
]
}
],
Don't forget to set the keybindings to the Terminal: Change Color and Terminal: Change Icon commands in VsCode.
I would like to toggle the explorer.excludeGitIgnore setting on VS Code. I didn't find and command to toggle that flag. I was wondering whether there might by a command to update any setting.
I was thinking about something like this:
{
"key": "shift+cmd+.",
"command": "setting.edit",
"args": [
"explorer.excludeGitIgnore",
"true",
],
"when": "explorerViewletFocus"
},
I have a template, which defines all the typesetting recommendations for thesis, but it uses xelatex for compilation. I want to continue using VS Code with Latex Workshops, question is how to change compiler to xelatex from pdflatex. The last one cause next error log:
C:\Users\User\AppData\Local\Programs\MiKTeX 2.9\tex/latex/fontspec\fontspec.sty:45: Fatal Package fontspec Error: The
fontspec package requires either XeTeX or
(fontspec) LuaTeX.
(fontspec)
(fontspec) You must change your typesetting engine to,
(fontspec) e.g., "xelatex" or "lualatex"instead of
(fontspec) "latex" or "pdflatex".
The simplest solution found in issues here, but in more common formulation:
Copying the content, simply go to Preferences → Extensions → LaTeX (meaning LaTeX is LaTeX workshops), find gear-wheel button with name Manage, then find in the list link to settings.json under any tag, open and type next:
"latex-workshop.latex.tools": [{
"name": "latexmk",
"command": "latexmk",
"args": [
"-xelatex",
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
}],
Reloading the VSCode may be needed.
Also setting.json file could be found in C:\Users\*\AppData\Roaming\Code\User\settings.json.
Use magic comments
add the following line to the beginning of your document.
% !TEX program = xelatex
To enable magic comments, change the setting forceRecipeUsage to false.
I kept getting errors with the other solutions, apparently because I was using backend=biber in my latex code. The following configuration assumes a current MiKTeX setup (including biber) and fixes those problems (also, this does not rely on latexmk). The config uses some inspiration from that of TeXworks.
Inside latex-workshop.latex.tools
{
"name": "xelatex",
"command": "xetex",
"args": [
"-undump=xelatex",
"%DOC%.tex"
],
"env": {}
},
{
"name": "biber",
"command": "biber",
"args": [
"%DOC%"
],
"env": {}
}
Then inside latex-workshop.latex.recipes add the recipe:
{
"name": "xelatex ➞ biber ➞ xelatex x 2x",
"tools": [
"xelatex",
"biber",
"xelatex",
"xelatex"
]
}
Happy texing!
I'm trying to create a custom package and one thing I would like to do is bring up the Build Systems(located in the Tools menu item) in the command palette(show_overlay). So I have tried to create a Default.sublime-commands file in my package and type in...
[
{ "caption": "Build System", "command": "build_system" }
]
...to enable that menu item for the command palette(I also tried set_build_system) and then I created a Default.sublime-keymap file in my package so that I can access the Build System list from via shortcut...
[
{
"keys": ["f9"], "command": "show_overlay",
"args": {"overlay": "command_palette", "text": "Build System"}
}
]
I am not having any luck exposing the Build System menu item to the command palette. Can I get some help on this? I also noticed the Tools menu item is not available in the command palette as well. What am I missing?
Ok I figured it out. The command palette can only be populated by existing commands that run in sublime. The way you can view which commands that are being run in sublime is to open up the console(CTR + ~) and type in sublime.log_command(True)
Now whenever you do anything that makes sublime trigger a command, it will log that action in the console. Armed with this knowledge, we we go to Tools > Build System and click on the build system type we want, say, C++, we get:
command: set_build_system {"file": "Packages/C++/C++.sublime-build"}
Sweet! Knowing this we can go to our .sublime-commands file(you can call it Default.sublime-commands) and type in the below code:
[
{
"caption": "Set Build System: C++", "command": "set_build_system",
"args": { "file":"Packages/C++/C++.sublime-build" }
}
]
Tip: pay close attention to the "caption" it's what we will use to tie our .sublime-command file with our .sublime-keymap file. Let's add another one build system:
[
{
"caption": "Set Build System: C++", "command": "set_build_system",
"args": { "file":"Packages/C++/C++.sublime-build" }
},
{
"caption": "Set Build System: Python", "command": "set_build_system",
"args": { "file":"Packages/Python/Python.sublime-build" }
}
]
Now that we have exposed these two commands in our .sublime-commands file. We can create a shortcut for it in our .sublime-keymap file. I called mine Default.sublime-keymap:
[
{
"keys": ["f8"], "command": "show_overlay",
"args": {"overlay": "command_palette", "text": "Set Build System:"}
}
]
Notice the "text" key. Look familiar? This is how you connect your key binding to your command. Save press F8 and boom! You have our own custom command palette menu. Enjoy!
PS: you can put your .sublime-commands/.sublime-keymap files in your User package or add to any existing ones if you have them there if you just want to customize your sublime text 2 without making a custom package.