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'"
}
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"
}
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"
},
I've been using alt+s to escape in vim for a while. I'm now considering to try VSCode with its vim plugin. Is it possible to map alt+s to extension.vim_escape? Currently, alt+s opens "Selection" from the top menu bar.
I have tried adding the following to keybindings.json
{
"key": "alt+s",
"command": "extension.vim_escape"
}
as well as the following to settings.json
"vim.insertModeKeyBindings": [
{
"before": ["alt+s"],
"after": ["<Esc>"]
}
],
What worked for me was putting this binding into keybindings.json and reloading the editor.
[
{
"key": "alt+s",
"command": "extension.vim_escape",
"when": "editorTextFocus && vim.active && vim.mode == 'Insert'"
}
]
This old Emacs user, who is used to elpy, is attempting to move onto VSCode with Scala & more specifically Ammonite repl.
I used Ctrl+' to open the integrated terminal & all I have to do is type amm on the bash shell (ubuntu) to open the repl; however, I still miss being able to send the either the line or selection from the editor to integrated shell with Ctrl+Enter.
I guess this means a bit of coding. Where can I start? Has anyone accomplished similar?
Thanks much,
If you already have your terminal and REPL open, there is a built in command called "Run Selected Text in Active Terminal" / workbench.action.terminal.runSelectedText.
It has no default keybinding, so you need to set it yourself. Something like this would work:
{
"key": "ctrl+enter",
"command": "workbench.action.terminal.runSelectedText",
"when": "editorTextFocus && editorHasSelection"
}
Actually, I found that adding VSCode Macros extension does the job:
I just changed settings.json:
{
"window.zoomLevel": 1,
"editor.fontSize": 11,
"terminal.integrated.fontSize": 11,
"macros": {
"execCurLn": [
"cursorUp",
"expandLineSelection",
"workbench.action.terminal.runSelectedText",
"cancelSelection"
]
}
}
and added (1st part is pure #kwood & thank u again) to keybindings.json
{
"key": "ctrl+enter",
"command": "workbench.action.terminal.runSelectedText",
"when": "editorTextFocus && editorHasSelection"
}
{
"key": "ctrl+enter",
"command": "macros.execCurLn",
"when": "editorTextFocus && !editorHasSelection"
},
{ "key": "ctrl+`", "command": "workbench.action.terminal.focus"},
{ "key": "ctrl+`", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"}
Open the command palette with CTRL+SHIFT+P and look for Terminal: Run Selected Text In Active Terminal. On the left you will see the key binding or a wheel engine to set the binding.
follow another post VS Code move to next line on run ctrl + enter, to run current line then cursor down, avoiding running next line unexpectedly
in settings.json, add
"macros": {
"pythonExecSelectionAndCursorDown": [
"python.execSelectionInTerminal",
"cursorDown",
]
}
in keybindings.json, add
{
"key": "ctrl+enter",
"command": "macros.pythonExecSelectionAndCursorDown",
"when": "editorTextFocus && editorLangId == 'python'"
},