Is it possible to quickly swap lines in VS Code? - visual-studio-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.

Related

Alt-based shortcuts in VS Code's intergrated terminal

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 :-(.

Is there a shortcut to switch between code panels in Spyder 5.2.1?

I'm currently new to Spyder and I'm trying to get a feel for the shortcuts.
I have seen that you can actually create multiple code panes using split vertical/horizontal (in order to work on multiple code files), however I didn't find any shortcut to switch between the multiple code panels I had.
So, is there any shortcut to move my text cursor from A panel to B panel ?
(Spyder maintainer here) There's no keyboard shortcut for that, sorry.

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.

Multi-Line select with Alt

How can I select multi-line with vscode?
On Visual Studio you can press left alt key and select multi-lines, but it is not working with vscode.
As of May 2017, it is possible. Read the release notes:
We have introduced a new setting, editor.multiCursorModifier, to
change the modifier key for applying multiple cursors to Cmd+Click on
macOS and Ctrl+Click on Windows and Linux. This lets users coming from
other editors such as Sublime Text or Atom continue to use the
keyboard modifier they are familiar with.
The setting can be set to:
ctrlCmd - Maps to Ctrl on Windows and Cmd on macOS.
alt - The existing default Alt.
It is not available for now, but there is a feature request on uservoice:
http://visualstudio.uservoice.com/forums/293070-visual-studio-code/suggestions/7761561-vertical-text-selection
The box-selection feature in Visual Studio (where you can highlight a part of multiple lines) isn't available in VSCode.
For features like this that you would love to see in VSCode - you can add the idea to the Code User Voice pages.

Ctrl+Backspace/Option+Delete fails to delete previous word in MATLAB IDE

I've noticed that Ctrl+Backspace/Option+Delete doesn't delete the word to the left of cursor in the MATLAB editor, as it does in many (most?) other editors and programs. This is intensely annoying, as I often will want to change a function name or small section of code. Currently I am forced to hold shift, use option+left, and then press delete to perform what should be a two keystroke operation.
Is there a way to enable it, or is a similar shortcut available? I found this unanswered question on MATLAB Central, but no further joy.
Edit:
Running R2010a on OSX
Are you on R2010b?
At least on Windows, this is supported starting in R2010b. All the keyboard shortcuts are in File > Preferences, under Keyboard > Shortcuts. Type "word" in the search bar (the text field just above the list of actions) to see the word-level actions. In R2010b, but not earlier versions, there is a "Remove Previous Word" action, and in Windows it's bound by default to Ctrl+Backspace. Sounds like you're using Mac, too; I don't know what the default binding is there.
So, upgrade to R2010b, and maybe adjust the bindings under Keyboard > Shortcuts in Preferences.
This and some other keyboard shortcuts work in the editor but not in the command window. I don't know why. You might want to request that as an enhancement from MathWorks if you want it in the command window, too.