Reputation: 4071
How does one switch the case of highlighted text in Visual Studio Code? VS allows this via CTRL+SHIFT+U and CTRL+U.
Is there a command binding that I can set up to do this, or is it by default some other key combination?
Upvotes: 378
Views: 293943
Reputation: 1105
Quoted from this post:
The question is about how to make CTRL+SHIFT+U work in Visual Studio Code. Here is how to do it. (Version 1.8.1 or above). You can also choose a different key combination.
File-> Preferences -> Keyboard Shortcuts.
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: To open the JSON editor, click this icon in the top right corner:
Upvotes: 109
Reputation: 1282
To be clear by using pictures, you can create a KEYBINDG
easily on macOS
like following;
1- Press SHIFT
+COMMAND
+P
and type lower
then click settings
icon
2- Right click and the Add binding
3- Press
the desired key combination and then press ENTER
4- Close the tab and then select an UPPER CASE
text and press your key combination. Magically, it will be upper case
:)
Upvotes: 3
Reputation: 9011
Use the shortcut Ctrl + Shift + P to open the command palette prompt.
In the command, palette start typing the text casing you wish to transform e.g lowercase or uppercase then select the appropriate option that you are presented as shown in the figure below.
Upvotes: 22
Reputation: 6852
Echoing justanotherdev's comment:
Mind-blowing and useful:
CTRL
+ SHIFT
+ p
(Mac: CMD
+ SHIFT
+ p
)>transform
pick upper/lower case and press enterUpvotes: 552
Reputation: 13759
Now an uppercase and lowercase switch can be done simultaneously in the selected strings via a regular expression replacement (regex, CtrlH + AltR), according to v1.47.3 June 2020 release:
This is done through 4 "Single character" character classes (Perl documentation), namely, for the matched group following it:
[[:lower:]]
: first character becomes lowercase[[:upper:]]
: first character becomes uppercase[^[:lower:]]
: all characters become lowercase[^[:upper:]]
: all characters become uppercase$0
matches all selected groups, while $1
matches the 1st group, $2
the 2nd one, etc.
Hit the Match Case button at the left of the search bar (or AltC) and, borrowing some examples from an old Sublime Text answer, now this is possible:
(\s)([a-z])
(\s
matches spaces and new lines, i.e. " venuS" => " VenuS")$1\u$2
(\s)([A-Z])
$1\l$2
([a-z])([A-Z])
$1\l$2
(\w)([A-Z]+)
$1\L$2
\L$0
(\w)([A-Z]+)
$1\U$2
(\w+)([A-Z])
\U$1$2
(\w+)([A-Z])
\L$1$2
([A-Z])(\w+)
$1\U$2
([A-Z])(\w+)
$1\L$2
([a-z\s])([A-Z])(\w)
$1\l$2\u$3
(\w)([A-Z])([a-z\s])
\u$1\l$2$3
Upvotes: 16
Reputation: 11732
To have in Visual Studio Code what you can do in Sublime Text ( CTRL+K CTRL+U and CTRL+K CTRL+L ) you could do this:
Between the []
brackets add:
{
"key": "ctrl+k ctrl+u",
"command": "editor.action.transformToUppercase",
"when": "editorTextFocus"
},
{
"key": "ctrl+k ctrl+l",
"command": "editor.action.transformToLowercase",
"when": "editorTextFocus"
}
Save and close "keybindings.json"
Upvotes: 18
Reputation: 151
For those who fear to mess anything up in your vscode json settings this is pretty easy to follow.
Open "File -> Preferences -> Keyboard Shortcuts"
or "Code -> Preferences -> Keyboard Shortcuts"
for Mac Users
In the search bar type transform
.
By default you will not have anything under Keybinding
. Now double-click on Transform to Lowercase
or Transform to Uppercase
.
Press your desired combination of keys to set your keybinding. In this case if copying off of Sublime i will press ctrl+shift+u
for uppercase or ctrl+shift+l
for lowercase.
Press Enter
on your keyboard to save and exit. Do same for the other option.
Enjoy KEYBINDING
Upvotes: 15
Reputation: 12601
I've written a Visual Studio Code extension for changing case (not only upper case, many other options): https://github.com/wmaurer/vscode-change-case
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 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.
The change-case extension is still useful for other text transformations, e.g. camelCase, PascalCase, snake-case, etc.
Upvotes: 77
Reputation: 1682
I think this is a feature currently missing right now.
I noticed when I was making a guide for the keyboard shortcut differences between it and Sublime.
It's a new editor though, I wouldn't be surprised if they added it back in a new version.
Source: https://code.visualstudio.com/Docs/customization
Upvotes: 0