How do I bind "Enter" to a command in vscode? - visual-studio-code

I went to Code->Preferences->Keyboard Shortcuts to bind ENTER to the "acceptSelectedSuggestionOnEnter" command (somehow my vscode stopped letting me accept input suggestion by pressing Enter...), but I wasn't able to enter ENTER by pressing it when it asked me to "press desired key combination and then press ENTER" because the entry box closes on ENTER.
vs code version: 1.72.2
On a Mac
Does anyone know how to do this? Many thanks!

Related

VsCode Accept Suggestion on enter Not Working :(

Normally, pressing enter accepts a suggestion on intellisense, but when I press enter, it does not accept the suggestion and goes to the next row.
On pressing enter, I want to accept to the currently selected suggestion and automatically write the row. How can this be done?
Go to File>Preferences>Settings and make sure that Accept Suggestions On Enter is on.
VSCode Accept Suggestion On Enter option

How can I get CTRL+K CTRL+E to work in terminal

I don't use these specific control commands in vs code. But I do use them on the terminal all the time.
How can I configure VSCode to send them to the terminal?
When press CTRL+E or CTRL+K, it says:
waiting for the second key of chord.
CTRL+A works in the terminal just fine, so I figured I'd either have to set something or unset something, but I've had zero luck in tracking that down.

Save with "Retry as Sudo" using keyboard commands

Anytime I try to save a file (using Ctrl+S) that requires elevated permissions, I get the popup with the button to "Retry as Sudo". This is fine, but there does not seem to be any way to select "Retry as Sudo" using the keyboard. I have to use the mouse to actually click the "Retry as Sudo" button. I have tried tabbing, but cannot seem to select this button without using the mouse. Does anyone know if there is anyway to save a file as sudo without using the mouse?
From https://github.com/microsoft/vscode/issues/90661#issuecomment-586422989:
Create keyboard shortcut for command notifications.focusToasts
When the Retry as Sudo toaster appears you can now:
Press the assigned shortcut
Press Tab
Press Enter
I wanted to include an example to complement the other answers.
To add a keybinding open the command pallet:
ctl+shift+p Windows
cmd+shift+p MacOS
Search for >Open Keyboard Shortcuts (JSON) and press enter.
https://code.visualstudio.com/docs/getstarted/keybindings#_advanced-customization
Below is an example that you can copy and paste as is into the json document. If there are no existing custom bindings just place it in between the [ ] brackets. If there are existing bindings (denoted by { } brackets) make sure you use a comma to separate them.
{
"key": "ctrl+shift+l",
"command": "notifications.focusToasts",
}
To be clear you will need to first save to bring up the "save as sudo" notification. Then you press the hotkey combination (which focuses the notification), then press TAB to highlight the "save as sudo" button, then press Enter to save.
It's not ideal, but it works.

Visual Studio Code view command run by last input

I'm trying to figure out which editor command is used when I press keys in different contexts. For example, I want to know which editor command is run when I press DownArrow while the quick fix widget is open, as shown:
How can I find out which command is run when I press a key in VS Code? The Keyboard Shortcuts search-by-key capability does not solve my problem.

How to run the select code in VScode?

I want to run the select code of python in VScode. Till now, I have to copy the code and paste it in the terminal below to run. The system is mac OS.
So is there any way to run the code directly after I selected the code? For example, like the shortcuts.
Thanks.
There is no default keybindings for command "Run Selected Text in Active Terminal", but you can create one.
Press Ctrl+K, Ctrl+S to open File → Preferences → Keyboard Shortcuts.
Search for workbench.action.terminal.runSelectedText in keybindings.
Press the icon on the left to open a windnow with this message "Press desired key combination..." and make your choice. (I've pressed Ctrl+Alt+R - as this combination was not used yet.)
Press Enter to store your keybinding.
Tested on VSCode 1.30.2 on Windows 10 Pro.
#yanachen, this is now possible in VS Code. All you need to do is:
1. Ensure python is running in the VS Code terminal window
2. Select the text you wish to execute in python
3. Invoke the command 'workbench.action.terminal.runSelectedText' as defined in the following link:
https://code.visualstudio.com/docs/editor/integrated-terminal#_key-bindings
Now it's supported by default shortcut "shift" + "enter".
select the proper code snippet
press "shift" + "enter"
Here is the setting for running selection in "interactive window."
In my VS Code (version 1.56.2), I do the following things: go to Settings, search for interactive window, in the resulting left panel choose Jupyter, and finally check the box next to Jupyter: Send selection to interactive window. That's it. One more step for some users (including me) is to modify the keybinding for running selection to your preference. For example, got to keyboard shortcuts, type run selection, you should see a list of keybindings and you may need to redefine them if conflicts exist.
Some language specific extensions have already an existing keybinding.
On Windows, for the PowerShell extension it is currently F8 to run the selected text.
Install the vscode extension Node.js Exec. then select the block of code you want to run and press f8. worked for me.