In VS2017 when use Ctrl+Del to delete a word, it will auto delete any following whitespaces.
Is it available to config VSC to working same way?
I don't think there is any built-in setting to do that. You would either have to just hit Ctrl-Del twice
or set up a macro to run that command twice.
Using the multi-command macro extension, puth is into settings.json:
"multiCommand.commands": [
{
"command": "multiCommand.deleteWordAndWhieSpaceRight",
"sequence": [
"deleteWordRight",
"deleteWordRight",
]
}
]
and in keybindings.json:
{
"key": "ctrl+delete",
"command": "-deleteWordRight",
"when": "textInputFocus && !editorReadonly"
},
{
"key": "ctrl+delete",
"command": "multiCommand.deleteWordAndWhieSpaceRight",
"when": "textInputFocus && !editorReadonly"
},
Related
I am working on OS Ubuntu 22.04 running inside a Virtualbox VM hosted in a windows 10 OS.
Inside the VM, it seems that my VScode has reset some of the user-defined keyboard shortcuts I have previously set.
So I want to re-define them.
I want to change the keyboard shortcut of "Toggle Line Comment", which is set from CTRL + Y to CTRL + ù ( currently CTRL + Y is assigned by the system to "redo", and that is OK ).
So I click on the pencil icon of "Toggle Line Comment",
press the keys combination CTRL + ù
"ù" gets interpreted as "[Backslash]"
press enter
but then I still see assigned CTRL + Y (as if the change was rejected); and from some tests I did, that one is the only combination that manages to toggle comment lines.
I have tryed to restart VScode but nothing changes, I cannot edit the settings from the UI.
So I have tryed to edit them from the keybindings.json
tommaso#tommaso-VirtualBox02:~$ sudo locate keybindings.json
/home/tommaso/.config/Code/User/keybindings.json
tommaso#tommaso-VirtualBox02:~$ vim /home/tommaso/.config/Code/User/keybindings.json
And the content of the opened file is
[
{
"key": "ctrl+alt+[Backslash]",
"command": "editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+shift+a",
"command": "-editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+shift+7",
"command": "-editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+[Backslash]",
"command": "editor.action.commentLine"
}
]
It is indeed strange that the last {} entry I have added via the UI is missing the "when" key.
Anyway I have edited the content to
[
{
"key": "ctrl+alt+[Backslash]",
"command": "editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+shift+a",
"command": "-editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+shift+7",
"command": "-editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+[Backslash]",
"command": "editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
}
]
saved,
restarted VScode
but again, the "toggle line comment" gets activated only by CTRL + Y.
The strange thing is that the CTRL + ALT + ù, that is
{
"key": "ctrl+alt+[Backslash]",
"command": "editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
}
works fine.
It is like VS code cannot load changes from keybindings.json .
What can be blocking the edit?
I believe you would do this like so:
[
{
"key": "ctrl+\\",
"command": "editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+y",
"command": "-editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
]
From another machine having the same key VScode shortcut configuration, and having the shotcuts properly working on VScode, I accessed the content of keybinding.json, and it is the following
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "ctrl+shift+[Backslash]",
"command": "editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+shift+a",
"command": "-editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+[Backslash]",
"command": "editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+shift+7",
"command": "-editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
}
]
It is exactly the same content of the one on the other machine, for which it was not working properly.
So the problem is machine-related.
So the end I have set the key combination ctrl+à for the toggle line comment, and it is OK.
I think the problem is somehow linked to how VScode interprets a key:
I have an italian keyboard having a key which contains "§" and "ù", but VS code somehow interprets it as "[Backslash]".
Once again I want to underline that it is strange to me that
ctrl+alt+ù
is correctly got as change by VScode, while
ctrl+ù
is rejected ( the UI swithces the combination automatically to "ctrl"+"y", while on the keybindings.json it is actually written "ctrl+[Backslash]" )
even if in both cases 1) and 2), "ù" is interpreted as "[Backslash]".
VScodevim has extension.vim_ctrl+j by default mapped to Ctrl+j which allows you do navigate down pop-up code suggestion windows (triggered by hitting Ctrl+Space in insert mode) like this:
It also has extension.vim_ctrl+k mapped to Ctrl+k but this binding down not work, so I cannot scroll up pop-up code suggestion windows. in insert mode defaults to entering a digraph but simply adding something like this
{
"before": ["<C-k>"],
"after": ["extension.vim_ctrl+k"]
}
to my settings.json does not work since although it removes the digraph functionality, from what I understand, whenever I now press Ctrl+k in insert mode, VSCode will consult the settings.json, find the mapping of to "extension.vim_ctrl+k" which points it back to settings.json in a sort of infinite loop.
:h i_ctrl-j in vim reveals this keybind to be mapped to "Begin new line" so it seems VScode interprets "Begin new line" as navigating down a pop-up window in insert mode instead of it's usual vim behaviour of creating a new line and moving the cursor there, although not sure this is how it works. In any case, I could not find an equivalent vim command that perhaps VSCode could use to scroll up in pop-up windows. Any help would be much appreciated!
I got this working by copying the existing default keybinds for ctrl+p and ctrl+n which are used throughout VSCode by default for scrolling up and down.
I've used alt here in my keybinds.json file but you can easily replace it with ctrl to achieve what you want
keybinds.json
// Down Motion
{
"key": "alt+j",
"command": "cursorDown",
"when": "textInputFocus"
},
{
"key": "alt+j",
"command": "showNextParameterHint",
"when": "editorFocus && parameterHintsMultipleSignatures && parameterHintsVisible"
},
{
"key": "alt+j",
"command": "selectNextSuggestion",
"when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
},
{
"key": "alt+j",
"command": "list.focusDown",
"when": "listFocus && !inputFocus"
},
{
"key": "alt+j",
"command": "workbench.action.quickOpenSelectNext",
"when": "inQuickOpen"
},
// Up Motion
{
"key": "alt+k",
"command": "cursorUp",
"when": "textInputFocus"
},
{
"key": "alt+k",
"command": "showPrevParameterHint",
"when": "editorFocus && parameterHintsMultipleSignatures && parameterHintsVisible"
},
{
"key": "alt+k",
"command": "selectPrevSuggestion",
"when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
},
{
"key": "alt+k",
"command": "list.focusUp",
"when": "listFocus && !inputFocus"
},
{
"key": "alt+k",
"command": "workbench.action.quickOpenSelectPrevious",
"when": "inQuickOpen"
}
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.
I use Visual Studio Code to develop with PowerShell on a regular basis. I frequently will test out a single line of code by hitting F8 (aka. Run Selection). However, if I've scrolled up from the bottom of the Integrated Terminal, hitting F8 doesn't cause the Integrated Terminal to scroll down to the end of its buffer.
How can I configure VSCode, with the PowerShell Extension, to jump to the end of the Integrated Terminal buffer, when I execute the Run Selection command?
I don't see a built-in way to do this, but you should be able to use the macros extension. Add the following to the end of settings.json:
"macros": {
"PowerShellRunSelection": [
"workbench.action.terminal.scrollToBottom",
"PowerShell.RunSelection"
]
}
Then add a keybinding to keybindings.json as follows:
{
"key": "f8",
"command": "macros.PowerShellRunSelection",
"when": "editorTextFocus && editorLangId == 'powershell'"
}
Here is my setting for both f5 and f8
settings.json
"macros": {
"PowershellRunSelection": [
"workbench.action.terminal.scrollToBottom",
"PowerShell.RunSelection"
],
"PowershellRun": [
"workbench.action.terminal.scrollToBottom",
"workbench.action.debug.start"
]
}
keybindings.json
{
"key": "f8",
"command": "macros.PowershellRunSelection",
"when": "editorTextFocus && editorLangId == 'powershell'"
},
{
"key": "f5",
"command": "macros.PowershellRun",
"when": "editorTextFocus && editorLangId == 'powershell'"
}
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"
},
]