I'm looking for something that basically combines cmd+B (show/hide sidebar) and cmd+J (show/hide terminal).
I've tried searching around but everything seems like there's only one per. Thanks!
[ I assume you know about zen mode but are looking for something different. ]
I think the easiest way to do this is with a macro extension, here using multi-command.
Put this into your keybindings.json:
{
"key": "alt+u", // whatever keybinding you want
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.maximizeEditor",
"workbench.action.closePanel"
]
},
"when": "panelVisible && sideBarVisible"
},
{
"key": "alt+u",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.toggleSidebarVisibility",
"workbench.action.togglePanel",
"workbench.action.focusActiveEditorGroup"
]
},
"when": "!panelVisible && !sideBarVisible"
},
{
"key": "alt+u",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.toggleSidebarVisibility",
]
},
"when": "!panelVisible && sideBarVisible"
},
{
"key": "alt+u",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.togglePanel",
"workbench.action.focusActiveEditorGroup"
]
},
"when": "panelVisible && !sideBarVisible"
}
I made it, by using the when clauses, to be a toggle. So the same keybinding would close both the sideBar and Panel if they are open or open them both if they are both closed.
Then I added the last two cases where one or the other of the sideBar or Panel is closed but not both. You may not care about those two cases.
By the way, this will maximize the current editor group if there are multiple groups.
Related
First, I have a shortcut on VSCode to Wrap a text with the thing I'm typing.
<div>
Hello World
</div>
If I select "World" and use the Emmet: Wrap with Abbreviation shortcut and type span I can make this:
<div>
Hello <span>World</span>
</div>
But here's the thing :
I know we can create custom wrapping that are not the same on each side of the word we selected (source: VS Code : create custom snippet/shortcut)
{
"key": "ctrl+i",
"command": "editor.action.insertSnippet",
"args": {
"snippet": "{something}$TM_SELECTED_TEXT{/some other thing}"
},
"when": "editorTextFocus && editorHasSelection"
}
What I would like is to select my variable, then use the shortcut, and it will print what I need UNDER the selected line, and whitout breaking the current line where I come from.
For this example, I'm selecting the var $user_id, press shortcut, and then boom it will add the second line.
$user_id = User::where('user_name', $user_name)->get()->first()->id;
dd($user_id);
Here's a start:
{
"key": "ctrl+alt+c",
"command": "editor.action.insertSnippet",
"args": {
"snippet": " ==> here we need to find how to line break without spliting the code and then: <==
{console.log(}$TM_SELECTED_TEXT{)}"
},
"when": "editorTextFocus && editorHasSelection"
}
Do you think it is possible ? Maybe the solution is to use Keyboard Macro separately from VSCode ?
I came up with this solution, thanks to #Mark in comments, related to this thread : How can I insert a snippet on a new line with vscode?
Install Multi-command VSCode extension
Open the settings file of the extension (settings.json)
Implement your code (here's mine with console.log() and dd() )
"multiCommand.commands": [
{
"command": "multiCommand.console.log",
"sequence": [
"editor.action.clipboardCopyAction",
"editor.action.insertLineAfter",
{
"command": "editor.action.insertSnippet",
"args": {
"snippet": "console.log(\"$CLIPBOARD: \", $$CLIPBOARD)\n$0"
}
},
]
},
{
"command": "multiCommand.dd",
"sequence": [
"editor.action.clipboardCopyAction",
"editor.action.insertLineAfter",
{
"command": "editor.action.insertSnippet",
"args": {
"snippet": "dd($$CLIPBOARD);"
}
},
]
}
Implement the shortcut in your VSCode settings (keybindings.json)
{
"key": "ctrl+1",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.console.log" }
},
{
"key": "ctrl+2",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.dd" }
}
If I'm understanding your question correctly, you can probably just use $0 to show where your cursor will end and use \n to insert a line break.
However, I'm not entirely sure if this works when creating a snippet from the Keyboard Shortcut file, but it works from the snippet file so I'm assuming it'll work here.
Note: I have searched in Google and other SO posts, but none of them have helped me.
I know that we can move up or down with Alt+Arrow. Is there a way to move, let's say 25 lines up, at once? I don't want to press Alt+↑ 25 times.
Is there a plugin or a built-in feature to do this?
The reason I'm asking is that it's easier to move multiple lines at once due to the relative line numbers feature in VS Code.
I don't want to specify each number in keybindings.json (As seen here).
To make it easier to navigate the cursor in blocks of lines you could set a keybinding to jump 10 lines up or down at once (in your keybindings.json):
{
"key": "ctrl+up", // whatever keybinding you want
"command": "cursorMove",
"args": {
"to": "up",
"by": "line",
"value": 10 // change this if you want
},
"when": "editorTextFocus"
},
{
"key": "ctrl+down", // whatever keybinding you want
"command": "cursorMove",
"args": {
"to": "down",
"by": "line",
"value": 10 // change
},
"when": "editorTextFocus"
}
As noted in the comments, this comes from https://stackoverflow.com/a/48568520/836330 so upvote that.
You can use multi-command
Like in Photoshop when you move something Arrow moves 1 pixel, Shift+Arrow moves 20 pixels.
The Arrow key has no modifier combo unused so we have to choose a different key.
New keybindings to move up or down 10 lines
{
"key": "alt+numpad8", // or any other key combo
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction",
"editor.action.moveLinesUpAction"
]
},
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "alt+numpad2",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction",
"editor.action.moveLinesDownAction"
]
},
"when": "editorTextFocus && !editorReadonly"
}
Maybe you have to add a little delay
"args": {
"interval": 50,
"sequence": [
I do not think there is an option to achieve what you want with VS Code only but there is an extremely powerful Vim plugin which is based on Vim terminal text editor. You should check it out, you can do anything you imagine with it but it takes some time to get used to it.
https://marketplace.visualstudio.com/items?itemName=vscodevim.vim
I'm looking for a shortcut that would clear the debug console + the terminal, and that would work when my cursor is on the editor.
I tried this code in the keybindings.json which only works for the terminal, and when the cursor is on the terminal (unless I removed the "when" part). But in any case this doesn't clear the debug console.
{
"key": "ctrl+k",
"command": "workbench.action.terminal.clear",
"when": "terminalFocus"
},
{
"key": "ctrl+k",
"command": "workbench.debug.panel.action.clearReplAction",
"when": "inDebugRepl"
},
You will probably have to use a macro extension like multi-command that will allow you to run multiple commands.
In your settings.json:
"multiCommand.commands": [
{
"command": "multiCommand.clearTerminalandDebugConsole",
"sequence": [
"workbench.action.terminal.clear",
"workbench.debug.panel.action.clearReplAction"
]
}
]
and in keybindings.json:
{
"key": "ctrl+alt+k",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.clearTerminalandDebugConsole" },
// below since you wanted it to work with editor focus
"when": "editorTextFocus"
},
You used Ctrl-K but that is a sequence used in many already-bound conflicting commands, so I used Ctrl-Alt-K.
Any suggestions how to toggle between code and integrated terminal in VS Code?
In PowerShell ISE for example it's : Ctr+D terminal and Ctr+I code
Can't find anything similar for VS Code.
Thank you in advance for any suggestions
At current, the last post by sqlaide on this thread had a great answer (that works). You open up your keybindings.json* file and add the text below between the square brackets. Once complete, you can use Ctrl+` to move focus back and forth between the code and the terminal.
*File > Preferences > Keyboard Shortcuts and click on keybindings.json.
{
"key": "ctrl+`", "command": "workbench.action.terminal.focus",
"when": "!terminalFocus"},
{
"key": "ctrl+`", "command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"}
elaborating on the previous answer, I would like to share my working configuration to switch between Code and Terminal with or without full-sized Terminal.
NOTE: I tested this on my Mac, running VSCode on an EC2 instance.
settings.json
{
"multiCommand.commands": [
{
"command": "multiCommand.move2Terminal",
"sequence": [
"workbench.action.toggleMaximizedPanel",
"workbench.action.terminal.focus"
]
},
{
"command": "multiCommand.move2Code",
"sequence": [
"workbench.action.toggleMaximizedPanel",
"workbench.action.focusActiveEditorGroup"
]
}
]
}
keybindings.json
[
// Switch between Terminal and Code
{
"key": "shift+cmd+,",
"command": "workbench.action.terminal.focus",
"when": "!terminalFocus"
},
{
"key": "shift+cmd+,",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
}
// Switch to Terminal full-screen and back to Code
{
"key": "shift+cmd+.",
"command": "extension.multiCommand.execute",
"args": {
"command": "multiCommand.move2Terminal"
},
"when": "!terminalFocus"
},
{
"key": "shift+cmd+.",
"command": "extension.multiCommand.execute",
"args": {
"command": "multiCommand.move2Code"
},
"when": "terminalFocus"
},
]
Introduction
I am creating an extension in Visual Studio Code that creates a 'quickPick' menu from which the user can select options:
I can use the up and down arrows to scroll through the list, but I want to be able to bind this to something more home-row friendly like ctrl-n and ctrl-p. I have ctrl-n and ctrl-p already bound for scroll up/down on the main command menu (ctrl-shift-p), and I was hoping the quick pick would fall under this rule as well. Unfortunatley, none of my many ctrl-n context bindings are taking effect.
I'm hoping for something I can add to 'keybindings.json' that looks something like:
{
"key": "ctrl+n",
"command": "cursorDown",
"when": "quickPickFocus"
},
But I can't see anything like this when browsing through the "Default Keyboard Shortcuts".
Questions
How do you create key bindings for quick pick lists?
Can I possibly create a custom "when" context for my extension? Then I can specify something like:
"when" : "myExtensionIsActive && blah"
Additional Doc
Here are all the overridden ctrl-n key bindings in my keybindings.json:
{
"key": "ctrl+n",
"command": "cursorDown",
"when": "editorTextFocus"
},
{
"key": "ctrl+n",
"command": "workbench.action.quickOpenNavigateNext",
"when": "inQuickOpen"
},
{
"key": "ctrl+n",
"command": "showNextParameterHint",
"when": "editorTextFocus && parameterHintsVisible"
},
{
"key": "ctrl+n",
"command": "selectNextQuickFix",
"when": "editorFocus && quickFixWidgetVisible"
},
{
"key": "ctrl+n",
"command": "selectNextSuggestion",
"when": "editorTextFocus && suggestWidgetVisible"
},
Here is the code where I create the quickPick:
var themeList = this.getThemeList()
vscode.window.showQuickPick(themeList)
.then(val => {
// Update the status bar
this.cmdChannel.text = `Theme: ${val}`
this.cmdChannel.show();
});
You just add wrong key binding command and when, please try to add this to your keybindings.json
{
"key": "ctrl+n",
"command": "workbench.action.quickOpenSelectNext",
"when": "!editorFocus"
},
{
"key": "ctrl+p",
"command": "workbench.action.quickOpenSelectPrevious",
"when": "!editorFocus"
}