Alt-based shortcuts in VS Code's intergrated terminal - visual-studio-code

My shell is configured to have Alt+n and Alt+p navigate in history (technically, using zsh's history-beginning-search-forward and history-beginning-search-backward).
I used to be able to use these shortcuts in VS Code's integrated terminal, but since I upgraded to VS Code 1.74.1, the Alt+n and Alt+p seem to be catched by VS Code before reaching my shell (the cursor changes to a cross to allow rectangular selection when I press Alt, which I guess is the cause). I do have "terminal.integrated.sendKeybindingsToShell": true and "terminal.integrated.allowMnemonics": false in my settings to avoid interference between VS Code and the Alt key, and I couldn't find another setting to change the behavior. Surprisingly, the Alt+a command is passed to the shell, so some Alt-based shortcuts are passed to the shell, but not all.
Is it possible to configure VS Code to send Alt+n and Alt+p to my shell?
As a workaround, using Alt+Shift+n and Alt+Shift+p seem to work, but that's one extra key to teach my fingers to use :-(.

Related

Shortcuts within Find/Replace dialog do not work in Visual Studio Code?

As shown in this screenshot there are 5 occurrences of the "Find" field. But hitting CMD-ENTER -as shown in the shortcut balloon help - does nothing.
Why is it not working/ what can be done to get it to to work? I detest using the mouse for extremely common operations especially Find/Replace.
It is a little odd that the binding is Cmd+Enter on the Mac, whereas it is Ctrl+Alt+Enter on Windows? Things to try:
The equivalent of Ctrl+Alt+Enter on the Mac (and you indicated that Cmd+Option+Enter does work).
Check in the Gear Icon/KeyboardShortcuts editor what the command editor.actions.replaceAll is bound to.
Check in the Keyboard Shortcuts (click on the little keyboard icon to the right and type Cmd+Enter) to see if it is bound to something besides editor.actions.replaceAll.
You can run the Developer: Toggle Keyboard Shortcuts Troubleshooting command from the Command Palette, type Cmd+Enter and see what command vscode finds for that keybinding.
You indicated that Cmd+Option+Enter does work as you expect.

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.

In Visual Code editor, how can I which functions a key is bound to?

In Visual Studio Code editor (not Visual Studio to which this answer and this answer applies) how can I know which function is bound to a particular keyboard shortcut?
I know about assigning a keyboard shortcut to a function and then using the conflict resolution option that the editor provides to resolve any overloaded keystrokes. What I want to know is how to find which function is assigned to a particular keystroke. Apparently, in Visual Studio (IDE) there's an option to use a "Shortcut currently used by" dialog so that you could type in a keystroke/chord and it would show the function (rather than execute it) (see links above). Emacs has the same type of thing where you can type a keystroke and see what it is bound to.
The backstory on this: I used to open the recent files list via ctrl+R. Recently it says "Waiting for second key of chord...". I can see that the recent files function is STILL bound to ctrl+R but short of eyeball browsing hundreds of commands I can't determine how to backtrack to find whatever is using the ctrl+R key chord.
Open your keyboard shortcuts preferences (⌘K ⌘S). The search input field has a keyboard icon on the right side. Click that - or press ⌥⌘K - to record keys and VS Code will show you all commands for that specific keybinding.

Is it possible to quickly swap lines in VS Code?

I'm currently experimenting with VS Code, having used Sublime Text 3 for the last five years or so. In Sublime, I could quickly swap two lines by selecting them both and then doing Ctrl+T.
As far as I've been able to find, the only equivalent command in VS Code is Alt+↑/↓, which pushes the selected line either up or down, and would be excruciatingly slow unless the selections are very close to each other.
Is this still true as of 2019? Is this basic functionality really not possible in VS Code?
There is no built-in functionality.
You can use a combination of VS Code's multi-cursor selection and the Swap extension.
Select one line or lines
Select another line/lines while holding down Alt or CMD (for Mac)
Use the extension's swap shortcut
Via keyboard shortcut
Windows: CTRL+ALT+8
Mac: CMD+OPTION+8
Via command palette
"Swap"
You can customize the keyboard shortcut to be same as what you used in Sublime.

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.