Make selected block of text uppercase - visual-studio-code

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

Related

Can VS Code input text when I type a rapid shift shift sequence?

So, my new keyboard doesn't have the pipe key, and I use it frequently (I'm learning elixir right now). I know that alt + 124 produces |, but it is a bit annoying to type it every time I want to use |> on elixir.
Is it possible to configure a shortcut (thought about something like shift shift) to insert |> in the editor?
Microsoft has its own tool to create custom layouts.
Microsoft Keyboard Layout Creator 1.4 Download.
Here is a brief how-to gracefully stolen from MakeUseOf
Open the Microsoft Keyboard Layout Creator app.
Head to File > Load Existing Keyboard.
Pick the layout you want to customize. You should make sure you pick the layout that matches your current keyboard setup, for example, QWERTY (U.S.).
Go to File > Save Source File As so you have a backup before you start making changes.
Set your new keyboard’s parameters in Project > Properties. You can pick a language and give the keyboard a name and description.
Click on a key and follow the on-screen prompt to remap it to a character of your choosing.
Assigning control keys combinations to input letters is not possible, AFAIK. Just set it so Shift+Something or to any 3rd level key. BTW, I am pretty sure your current 3rd level already has a pipe, to test it press the right Alt (also called AltGr) and press all the alphanumeric keys.
{
"key": "shift shift",
"command": "type",
"args": {
"text": "|>"
},
"when": "editorTextFocus"
}
Looks like using two modifier keys in rapid sequence will work soon. Commit merged: see Feature: Shift Shift, Ctrl Ctrl, Alt Alt Keybinds (Double press modifer keybind support)
Will be in v1.54 - works in the Insiders Build now.
You can define a keyboard shortcut
{
"key": "shift+alt+p",
"command": "type",
"args": { "text": "|>" },
"when": "editorTextFocus"
}
You can choose any key combo you like, see the docs

How to add multiple keyboard shortcuts to one command in VS Code?

How can I add multiple keyboard shortcuts to a single command in VS Code?
As an example (from the comments), ctrl + 0 & ctrl + 1 should both do the same command/action. So completely separate shortcuts doing the same command.
Let's say there are 2 bindings to close window like so:
Let's say we want to add one more keybinding like CMD+K, CMD+1. You could do that by right-clicking a command and choosing copy like so:
Then, click on an icon on the top right corner to open keyboard shortcuts JSON. The icon has an curved arrow on a page:
Your user-defined keybindings.JSON will show up. Type this in it:
// Place your key bindings in this file to override the defaults
[
{
"key": "cmd+k cmd+1",
"command": "workbench.action.closeWindow"
}
]
Save and close.
Now you will see 3 keybindings for the action like so:
Now, try your new keybinding.

What is the shortcut for CTRL + CLICK in Visual Code?

What is the shortcut key to Ctrl+Click (Follow Link) in Visual Code? If it doesn't have one, is there any way to add it?
In Eclipse, if I press F3 I can open the file, like Ctrl+Click
In HTML files the command is "Open Link" (editor.action.openLink). This command does not have, by default, associated a key combination. You can assign one by using the Preferences -> Keyboard Shortcuts command from the menu (click on the gear on the bottom of the primary side bar).
In other contexts (source code in various programming languages), the combination Ctrl+click (or Cmd+click on macOS) when the cursor is on an identifier (constant name, variable name, function name, class name, etc.) is equivalent with command "Go to Definition" (editor.action.revealDefinition). This command has, by default, associated the key F12.
Do Command/Control P > keybindings.json and insert:
[
...,
{
"key": "ctrl+f12",
"command": "editor.action.openLink"
}
]
to set Ctrl F12 to open the link under the cursor.

How to show uses of function in Visual Studio Code?

I am used from Pycharm to be able to press ctrl + click on a function definition and see the uses. Is there an equivalent in VSC?
you can use shift+f12 for get better view of usage
https://github.com/Microsoft/vscode-tips-and-tricks
read this and you can get better idea
2020-03-05 update
You can CTRL+CLICK (Windows) or CMD+CLICK (Mac) on the function name and look on the right column.
Right-click and select "Go to References" or "Find All References" from context menu:
There is, but VSCode doesn't support key bindings with mouse buttons. The relevant issue is #3130. That means that it will not work the same way as it works in PyCharm.
What You can do though is to use - I believe - ShiftF12 or set some key combination to show all usages of function.
To do this You can press CtrlK, then CtrlS and click on 'keybinding.json' link in the sentence: "For advanced customization open and edit keybinding.json".
After getting keybinding.json open, add the following entry there.
{
"key": "ctrl+shift+d",
"command": "editor.action.referenceSearch.trigger",
"when": "editorHasReferenceProvider && editorTextFocus && !inReferenceSearchEditor"
}
It should let You show usages of function by pressing CtrlShiftD. Obviously, You can customize it however You like.
I also recommend adding the following entry to close the dialog with the same key combination.
{
"key": "ctrl+shift+d",
"command": "closeReferenceSearch",
"when": "referenceSearchVisible && !config.editor.stablePeek"
}

Trigger advanced hover information with keyboard

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.