A few days ago VSCode recently self-updated to version 1.75.0 and the functionality of runSelectedText seems to have changed.
Previously, as I recall, if this command was called, highlighted text would be run in terminal without the cursor moving. Now, if this command is run, the cursor jumps from the editor to the terminal. I would like to either (i) change a setting somewhere (if it exists) so that this command doesn't jump to the terminal, or, (ii) work out a way of returning the cursor to the editor (e.g., with a macro).
I previously had this as part of a macro to highlight the current line (using the macros extension). I selected the current line, ran the text in terminal, then cancelled the selection.
So my main approach so far has been a number of variations on the workbench.action.focusActiveEditorGroup command to include this within a macro.
As a MWE, the following macro I have included in settings.json:
"macros": {
"runAndReturn": [
"workbench.action.terminal.runSelectedText",
"workbench.action.focusActiveEditorGroup" // <--- this doesn't work/do anything
],
},
For me, when I run this macro, it executes the current line as expected, but the cursor moves to the terminal and doesn't return back to the editor.
This issue was reported here: https://github.com/microsoft/vscode/issues/173247
It was caused here https://github.com/microsoft/vscode/commit/305de596d216fb925e3cc298c0b67ad99ad0b6c2
It was fixed here: https://github.com/microsoft/vscode/pull/173573
See the first link for some workarounds people found, which you can use while waiting for a version with the fix to be released:
Using ctrl+1 to focus the first editor group (or the number of whichever editor group you want to focus).
Found by anderswe: Using the multi-command extension with the following:
{
"key": "cmd+enter", // or ctrl+enter
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.terminal.runSelectedText", // run line
"workbench.action.focusActiveEditorGroup", // shift focus back to editor
"cursorDown" // jump to next line so you can spam cmd+enter
]
},
"when": "editorTextFocus"
}
You can use ctrl+j to toggle the visibility of the integrated terminal view.
I have VSCode configured to not search for text until I hit ENTER. But after I pull up search dialog, type text and hit ENTER, I have to hit ESCAPE to exit the search dialog.
Is there a way to disable that so after hitting ENTER, I am back to the editor without hitting ESCAPE?
I think the only way to do that is to "overload" the Enter key to do two things: (1) go to the next find match and (2) refocus the editor. For that you would need a macro extension like multi-command for example to run two commands in sequence.
In your keybindings.json:
{
"key": "enter",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"editor.action.nextMatchFindAction",
"workbench.action.focusActiveEditorGroup"
]
},
"when": "findInputFocussed"
}
This works in my testing.
I want to create a macro in sublime text using the number key on my keyboard. Is this possible?
My attempts have given me these results:
This works for the number 1 key on the keypad but not on the number 1 key on the keyboad
{"keys": ["alt+keypad1"], "command": "run_macro_file", "args": {"file": "Packages/User/action_self.sublime-macro"}}
This works for the f1 key on the keypad.
{"keys": ["alt+f1"], "command": "run_macro_file", "args": {"file": "Packages/User/action_self.sublime-macro"}}
This does not work!
{"keys": ["alt+1"], "command": "run_macro_file", "args": {"file": "Packages/User/action_self.sublime-macro"}}
It seems like the last mentioned should work. Is there a way to use the numbers of the keyboard to run macros?
Any help will be greatly appreciated!
That should work just fine. For example, under Windows/Linux, that key is bound by default to switch to the first tab in the current tab group:
{ "keys": ["alt+1"], "command": "select_by_index", "args": { "index": 0 } },
Possible problems with this include your operating system/window manager seeing the key and handling it before it gets to sublime or having a keyboard layout that makes that key not map to what you think it does.
To check both, open the Sublime console (View > Show Console from the menu or press Ctrl+`) and enter the command:
sublime.log_input (True)
This will make sublime output to the console whenever you press a key. Press Alt+1 and see what it displays in the console.
If nothing displays, something global is eating the key before Sublime gets to see it, which might be a shortcut in your OS of some sort.
Otherwise, it will display what key it thinks you pressed. If it shows you alt+1, then it's seeing the key and your key binding is just not taking effect for some other reason (wrong filename, the command does not do what you think it does, etc) which is a different issue.
If it shows you a key but not what you expect it to be, that's a result of your keyboard layout. In this case you can either switch to a different keyboard layout or just bind with the key as Sublime is reporting it.
Once you're done, you should run sublime.log_input (False) in the console to turn off input logging (or restart Sublime).
In vscode when I mouse hover on let's say, a method call or property it will display some information. I can trigger same thing with keyboard shortcut CMD+H (on mac).
Now with the mouse when I hover while holding the CMD key it will display more information. How to trigger this (CMD+mouse hover) equivalent with keyboard ?
(I'm aware of ALT+F12, but it's not exactly the same trigger.)
Per official docs, the binding for 'Show Hover' is:
⌘K ⌘I
Remember that ⌘K is a 'chord', so do that first (Code will show "⌘K was pressed. Waiting for second key of chord..."), and then ⌘I.
Hope this helps. It's not the most elegant of bindings, but nothing to stop you changing it!
Note:-
For VSCodeVim users, this is: gh.
For Windows users, this is: Ctrl + K Ctrl + I
This answer elaborates on Jack's helpful answer by pointing out the command palette command and how to override its shortcut.
Open the command palette and type "show hover" to find the command.
The default shortcut does not work for me, so I added an override of Ctrl + Space + H.
To add your own override, open the command palette and type "keyboard shortcuts". That opens the shortcut editor. This is how mine looks.
// Place your key bindings in this file to override the defaults
[
{
"key": "ctrl+space ctrl+h",
"command": "editor.action.showHover",
"when": "editorTextFocus"
}
]
There's a pull request to add this functionality, but it hasn't landed yet:
https://github.com/Microsoft/vscode/pull/59260
I think you are looking for keyboard shortcut for 'Definition Preview'.
command name: Show Definition Preview Hover
command:
editor.action.showDefinitionPreviewHover
To set a keyboard shortcut:
Open keyboard shortcuts
Search for Show Definition Preview Hover
Set your preferred shortcut
Add editorTextFocus to when expression
Or you can append this to your keybindings.json:
{
"key": "ctrl+alt+;",
"command": "editor.action.showDefinitionPreviewHover",
"when": "editorTextFocus"
}
Here ctrl+alt+; is shortcut key I have selected. You add your own.
Usefull reference:
https://code.visualstudio.com/updates/v1_40#_definition-preview-hover-from-the-keyboard
If you're using VSCodeVim, you can add this to your settings.json
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": ["g", "H"],
"commands": [
{
"command": "editor.action.showDefinitionPreviewHover"
}
]
}
]
By default if you enter gh it will open in hover state.
I have it configured so that if I press gH it shows me the advanced info.
Can I make a multi-line selection of text all capitals in Visual Studio Code?
In full Visual Studio it's CTRL+SHIFT+U to do this.
The extension that exists that I have seen only do non-multi-line blocks.
NOTE: THE UI OF VISUAL STUDIO CODE WHEN THIS QUESTION WAS ASKED (5 OR MORE YEARS AGO) HAS CHANGED.
The question is about how to make CTRL+SHIFT+U work in Visual Studio Code. Here is how to do it in version 1.57.1 or above.
Steps:
Open Visual Studio Code.
Press CTRL+SHIFT+P.
Type
open keyboard shortcuts
Select
Open keyboard shortcuts (json)
An editor will appear with keybindings.json file.
Place the following JSON in there and save:
[
{
"key": "ctrl+shift+u",
"command": "editor.action.transformToUppercase",
"when": "editorTextFocus"
},
{
"key": "ctrl+shift+l",
"command": "editor.action.transformToLowercase",
"when": "editorTextFocus"
}
]
Now CTRL+SHIFT+U will capitalise selected text, even if multi line. In the same way, CTRL+SHIFT+L will make selected text lowercase.
These commands are built into VS Code and no extensions are required to make them work.
Update August 2021
There is a UI to see and update keyboard shortcuts:
File-> Preferences -> Keyboard Shortcuts.
Find "Transform to Uppercase":
Click the + icon.
In the popup, press the desired key combination and hit enter:
Do the same for lower case.
Note
In the new versions (eg 1.57.x) of VS Code, Ctrl+Shift+L is a shortcut for bulk selecting all selected text occurrences. So you can use another combination, like Ctrl+Shift+/ etc.
Whenever you want to do something in VS Code and don't know how, it's a good idea to bring up the command palette with CTRL+SHIFT+P (CMD+SHIFT+P on mac), and try typing in a keyword for you want. Oftentimes the command will show up there so you don't have to go searching the net for how to do something.
Highlight the text you want to uppercase. Then hit CTRL+SHIFT+P to bring up the command palette. Then start typing the word "uppercase", and you'll see the Transform to Uppercase command. Click that and it will make your text uppercase.
Creator of the change-case extension here. I've updated the extension to support spanning lines.
To map the upper case command to a keybinding (e.g. CTRL+T+U), click File -> Preferences -> Keyboard shortcuts, and insert the following into the json config:
{
"key": "ctrl+t ctrl+u",
"command": "extension.changeCase.upper",
"when": "editorTextFocus"
}
EDIT:
With the November 2016 (release notes) update of VSCode, there is built-in support for converting to upper case and lower case via the commands editor.action.transformToUppercase and editor.action.transformToLowercase. These don't have default keybindings. They also work with multi-line blocks.
The change-case extension is still useful for other text transformations, e.g. camelCase, PascalCase, snake_case, kebab-case, etc.
Update on March 8, 2018 with Visual Studio Code 1.20.1 (mac)
It has been simplified quite a lot lately.
Very easy and straight forward now.
From "Code" -> "Preferences" -> "Keyboard shortcuts"
From the search box just search for "editor.action.transformTo",
You will see the screen like:
Click the "plus" sign at the left of each item,
it will prompt dialog for your to [press] you desired key-bindings,
after it showing that on the screen, just hit [Enter] to save.
In Linux and Mac there are not default shortcuts, so try to set your custom shortcut and be careful about don't choose a hotkey used (For example,
CTRL+U is taken for uncomment)
File-> Preferences -> Keyboard Shortcuts.
Type 'transfrom' in the search input to find transform shortcuts.
Edit your key combination.
In my case I have CTRL+U CTRL+U for transform to uppercase and CTRL+L CTRL+L for transform to lowercase
Just in case, for Mac instead of CTRL I used ⌘
Change letter case in Visual Studio Code
Updated answer
Show All Commands: Ctrl+Shift+P
and start typing "upper" or "lower" whichever command is highlighted, press Enter:
Note 1. The next time you use the function, it is usually enough to type the first letter of "upper" or "lower" words.
Note 2. You can also assign your own shortcut to these functions as they currently don't have any by default:
Original answer from 2017 (no longer valid for newer VSC versions)
To upper case: Ctrl+K, Ctrl+U
and to lower case: Ctrl+K, Ctrl+L.
Mnemonics:
K like the Keyboard
U like the Upper case
L like the Lower case
I think you can use
Select text
Ctrl+Shift+P
Enter Transform to Uppercase
Without defining keyboard shortcuts
Select the text you want capitalized
Open View->Command Palette (or Shift+Command+P)
Start typing "Transform to uppercase" and select that option
Voila!
At Sep 19 2018, these lines worked for me:
File-> Preferences -> Keyboard Shortcuts.
An editor will appear with keybindings.json file. Place the following JSON in there and save.
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "ctrl+shift+u",
"command": "editor.action.transformToUppercase",
"when": "editorTextFocus"
},
{
"key": "ctrl+shift+l",
"command": "editor.action.transformToLowercase",
"when": "editorTextFocus"
},
]
I'm using the change-case extension and it works fine.
I defined the shortcuts:
{
"key": "ctrl+shift+u",
"command": "extension.changeCase.upper",
"when": "editorTextFocus"
},
{
"key": "ctrl+u",
"command": "extension.changeCase.lower",
"when": "editorTextFocus"
},
Standard keybinding for VS Code on macOS:
Selection to upper case ⌘+K, ⌘+U
and to lower case: ⌘+K, ⌘+L.
All key combinations can be opened with ⌘+K ⌘+S (like Keyboard Settings), where you can also search for specific key combinations.
Select the text to transform.
Use Ctrl + L to selected the whole line
Open Show all commands.
Linux and Windows: Ctrl + Shift + P, Mac: ⇧⌘P
Type in the command, e.g. lower, upper, title
Hit Enter
On a Mac, in Visual Studio Code, its very easy to add a key binding to perform this action, it is not linked to a hotkey combo as a default though.
In the menu bar, navigate to: Code > Preferences > Keyboard Shortcuts
In the search bar that comes up, type: Uppercase
A entry will come up called "Transform to Uppercase"
Hover your mouse over that entry and click the plus sign just to the left of the words "Transform to Uppercase"
In the box that comes up push the keys you want to bind that action to (Cmd +Shift + U is taken so I chose Ctrl + Shift + U) then press enter and you're good to go.
Note this is working at the time of this writing in May of 2021