Every time I open vscode I have to click View->Appearance->Show panel or press Ctrl+J to open panel with console. Is it possible to run vscode with the panel open by default?
Vscode should remember whether the panel is open or not each time you close the window. But if it doesn't or you typically have it closed when you exit that vscode window and you have to Ctrl+J each time you open vscode try putting this task into your tasks.json:
{
"label": "open Panel",
"command": "${command:workbench.action.togglePanel}",
"type": "shell",
"problemMatcher": [],
"runOptions": {"runOn": "folderOpen"}
},
Now whenever the workspace opens, the togglePanel command will run automatically.
Related
Currently Ctrl+Enter runs code from the main directory.
I want to change this shortcut to run code from the integrated terminal directly.
My current workflow is:
right click file.py
Open in integrated terminal
type python file.py
Is there way to change the shortcut above to use the workflow instead.
If you want, you can make a task and assign a keybinding to it.
If you don't have a tasks.json file, go to the Command Palette (Ctrl+Shift+P if that hasn't been remapped), and enter Tasks: Configure Tasks, Configure tasks.json file from template, and Others. You should now have a tasks.json file.
The tasks key is an array, and you can insert an object there. For your case, you can have
{
"label": "Run python file",
"type": "shell",
"command": "py",
"args": ["${file}"],
"group": {
"kind": "build",
"isDefault": false
}
}
To have the keybinding, go to Keyboard Shortcuts (Settings > Keyboard Shortcuts [Ctrl + K Ctrl + S if this hasn't been remapped]) and click Open Keyboard Shortcuts (JSON).
There, define your own keybinding. For now, I choose F5F5, and we'll add this object.
{
"key": "f5 f5",
"command": "workbench.action.tasks.runTask",
"when": "editorLangId == python",
"args": "Run python file"
}
To explain, when we press F5 followed by F5 and we are an editor identified as a Python file, VSCode will run the command workbench.action.tasks.runTask. To choose which task VSCode will run, we'll provide the name of the task through the args key which is Run python file.
Is there any way to set vscode such that double-clicking a .docx file in the embedded file explorer causes the file to be opened in Microsoft Word?
Context
I'm used to PyCharm but I've been migrating to vscode. I'm used to creating Word document files (.docx) and double-clicking them in the file explorer on the left side sub-window to launch Word and see what the document looks like. This works in PyCharm, but in vscode it tries to open the file as a binary and claims it has no editor. Even if it did had an editor, I wanted it to open in my second monitor (or at least to be able to move it to my second monitor). For the time being, I'm opening a file explorer window and double clicking the file there, which has been less than optimal.
It's not quite double clicking, but you could create an open file command as a task, then bind that task to a keyboard shortcut, which amounts to one click and one hotkey.
Creating the open file task
We preferably make this task user-level, so that is accessible in every project.
ctrl+shift+p and search Tasks: Open User Tasks
In the tasks.json file, add the open file task to the tasks array:
// Inside "tasks": [ ... ]
{
"label": "open file",
"type": "shell",
"command": "${file}",
"presentation": {
// Hides the task terminal from showing up
"reveal": "never",
}
}
Change the "command" to whatever the open file command for your shell is (just ${file} works for windows, but change it to xdg-open ${file} for linux)
Assigning a keybinding to the open file task
To bind the task command to a keybinding, ctrl+shift+p and search keyboard shortcuts (JSON), open the file. Add the following to the array (changing "key" to whatever combination you desire)
// [ ... ]
{
"key": "ctrl+alt+l",
"command": "workbench.action.tasks.runTask",
"args": "open file"
}
To open any file, click on it to focus it in a tab (which sets the ${file} defined in tasks.json) and use the assigned hotkey. (As a side note, opening files that have vscode as their default program will open it in the same instance, so it makes it seem like the task isn't doing anything)
To work, Windows users should take care with command quotes
tasks.json :
{
"label": "open file",
"type": "shell",
"command": "'c:\\Program Files\\Microsoft Office\\root\\Office16\\WINWORD.EXE' '${file}'"
}
When I am in QuickOpen:
I would like to use "ctrl-v" to open this file in a split window.
Currently, I can do so with by "cmd+enter" in this QuickOpen dialog.
I can't seem to find the keybinding for this in the default keybinding json.
Can someone help me out?
{
"key": "ctrl+v"
"command": <--
"when": "inQuickOpen"
},
To be in v1.44:
New command to open editor to the side
A new command workbench.action.alternativeAcceptSelectedQuickOpenItem
allows to bind a key to open files or symbols from quick open to the
side.
From https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_44.md#quick-open-rewrite
So I presume this will work:
{
"key": "ctrl+v",
"command": "workbench.action.alternativeAcceptSelectedQuickOpenItem",
"when": "inQuickOpen"
},
Tested in standard version of vscode v1.44: this does work. It will open a file in a split editor from the QuickOpen panel.
I assume you already have the setting
Editor: Open Side by Side Direction
set to down. Only other option is right.
Currently, I have a Build Task set up in Visual Studio Code (not Visual Studio). When I press Ctrl+Shift+B, I get a list of my build tasks, I then have to select my task and then it will compile and run my program.
Is there an easier way to do this, so instead of Ctrl+Shift+B -> Enter, I can just press one button and have a preset Build Task run? Either a keyboard button or a GUI button will work great.
Mark the task as your default build task via Terminal -> Configure Default Build Task... This simply adds the following to the task in tasks.json:
"group": {
"kind": "build",
"isDefault": true
}
After that, Ctrl+Shift+B will run the task directly.
Additionally, you could also have a default test task with "kind": "test". That task can be directly run with the Tasks: Run Test Task command (no shortcut assigned by default).
And finally, if having two shortcuts is still not enough (or you don't want to modify tasks.json), you can set up keybindings to run tasks directly by their name:
{
"key": "ctrl+b",
"command": "workbench.action.tasks.runTask",
"args": "run"
}
Replacing run with the label of your Build Task.
To open keybindings.json press Ctrl+K Ctrl+S or click File -> Preferences -> Keyboard Shortcuts. You may need to add [] if the file was previously empty.
You can add this code in keybindings.json located at C:\Users\%User%\AppData\Roaming\Code\User\:
[
{
"key": "ctrl+shift+r",
"command": "workbench.action.tasks.runTask",
"args": "run"
},
// [...]
]
Source: https://lronaldo.github.io/cpctelera/files/buildsys/vscode_integration-txt.html
Pressing Ctrl+W closes the active editor window.
When no more editors are open, Ctrl+W terminates VSCode.
Could not find a related setting.
To me this is unexpected. Is it easy to prevent this?
Just realized that Ctrl+W is "close Window" while Ctrl+F4 is "close editor". Maybe I should just use the close editor command.
{
"key": "ctrl+w",
"command": "-workbench.action.closeWindow",
"when": "!editorIsOpen && !multipleEditorGroups"
},
Minus stands for "remove keybinding".
I had this issue on a new VSCode install today and was having troubles with the suggested answers I have seen.
Ultimately this was my solution
~/Library/Application Support/Code/User/settings.json
"window.closeWhenEmpty": false