298

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?

4
  • I can't find any relevant shortcuts in key bindings. Probably this function is not supported in the current version.
    – yushulx
    May 18, 2015 at 3:27
  • 4
    Update: it is supported now. Go to File > Preferences > Keyboard Shortcuts and search for "Transform".
    – Dinei
    May 8, 2017 at 16:16
  • Any way to toggle letter? Dec 13, 2022 at 8:37
  • I configure the key as shift + L and shift + U.
    – Eric
    Feb 28 at 18:31

8 Answers 8

428

Echoing justanotherdev's comment:

Mind-blowing and useful:

  1. Command Palette: CTRL + SHIFT + p (Mac: CMD + SHIFT + p)
  2. type >transform pick upper/lower case and press enter

enter image description here

5
  • 34
    It's possible to configure keybindings for this commands on File > Preferences > Keyboard Shortcuts
    – Dinei
    May 8, 2017 at 15:59
  • 3
    pycharm uses the same command CTRL+SHIFT+ "u" to toggle. why create 2 shortcuts when one could be used? i realize this is not an answer, just a comment.
    – davidj411
    Aug 24, 2018 at 16:46
  • 1
    sometimes you have "Mixed casing Text" that you want to go directly to "ALL UPPERCASE" or "all lowercase", so transforming to uppercase and transforming to lowercase separately make more sense. May 2, 2020 at 4:47
  • very useful particularly with multiple selections May 17, 2021 at 14:16
  • 1
    How to combine transform with "rename" meaning it automatically updates the same variables (F2). May 25, 2022 at 19:39
83

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.

8
  • Cool! This is the answer the question is asking for!
    – Nowdeen
    Nov 19, 2017 at 15:53
  • I went for cmd+shift+u and cmd+shift+l on macOS. Feels just right.
    – theory
    Mar 27, 2018 at 15:03
  • For Linux ctrl+shift+u is not working, so instead use key ctrl+u for uppercase & ctrl+l for lowercase May 12, 2018 at 5:33
  • 1
    Is it possible to have one keyboard shortcut cycle through each option instead of having separate keyboard shortcuts for each one? That is, can I set it up so that hitting shift+f3 changes it ToUppercase, hitting shift+f3 changes it ToLowercase, hitting it again changes it ToSnakecase, and hitting it again changes it ToTitlecase?
    – coip
    Jan 4, 2022 at 21:16
  • 3
    To find this hidden JSON editor with VS Code 1.72.2 (Sept. 2022) or later, click on the blank page icon with the curved arrow, which points to that blank page. It's in the upper right hand corner after using File-> Preferences -> Keyboard Shortcuts. Look for the 3 dots icon. It's the 1st icon on the left, before the split pane icon. The alt text says "Open Keyboard Shortcuts (JSON)". That will open the keybindings.json file. Saving that file will automatically enable the changes, without relaunching VS Code.
    – Clomp
    Oct 15, 2022 at 20:16
73

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.

5
  • 1
    the "ctrl+t u" didn't work for me on the mac version. I used "ctrl+u" instead as it's not mapped by default to any action.
    – Shahar
    Jan 5, 2017 at 8:23
  • 17
    For lazy people: select the text, ctrl + p, type >transform pick lower or upper case then press enter Mar 23, 2017 at 5:49
  • An addendum to @justanotherdev's comment: it's possible to configure keybindings for this commands on File > Preferences > Keyboard Shortcuts
    – Dinei
    May 8, 2017 at 15:59
  • Isn't there a way to have these options show up in the right click menu (the way Nptepad++ does) ? Nov 28, 2018 at 15:07
  • @justanotherdev to be honest, that's a faster process for me though, plus it is already baked in and no need for 'Yet Another Extension'
    – KhoPhi
    Sep 1, 2020 at 12:58
16

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:

  • Open "Keyboard Shortcuts" with click on "File -> Preferences -> Keyboard Shortcuts"
  • Click on "keybindings.json" link which appears under "Search keybindings" field
  • 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"


Another way:
Microsoft released "Sublime Text Keymap and Settings Importer", an extension which imports keybindings and settings from Sublime Text to VS Code. - https://marketplace.visualstudio.com/items?itemName=ms-vscode.sublime-keybindings

2
  • 1
    I don't know if it's new, but when I did this all I had to do was put "uppercase" in the search box that appeared, then click a '+' to add a new mapping. Repeat with "lowercase" to cover the other direction and I was all set.
    – torpy
    Nov 2, 2018 at 19:54
  • ctrl+k ctrl+u is usually reserved for uncomment... i've set mine to alt+k alt+u and alt+k alt+l.
    – sam yi
    Feb 5, 2021 at 15:55
13

For those who fear to mess anything up in your vscode json settings this is pretty easy to follow.

  1. Open "File -> Preferences -> Keyboard Shortcuts" or "Code -> Preferences -> Keyboard Shortcuts" for Mac Users

  2. In the search bar type transform.

  3. By default you will not have anything under Keybinding. Now double-click on Transform to Lowercase or Transform to Uppercase.

  4. 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.

  5. Press Enter on your keyboard to save and exit. Do same for the other option.

  6. Enjoy KEYBINDING

12

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:

Replacing different text cases in one selection

This is done through 4 "Single character" character classes (Perl documentation), namely, for the matched group following it:

  • \l <=> [[:lower:]]: first character becomes lowercase
  • \u <=> [[:upper:]]: first character becomes uppercase
  • \L <=> [^[:lower:]]: all characters become lowercase
  • \U <=> [^[: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:

  1. Capitalize words
  • Find: (\s)([a-z]) (\s matches spaces and new lines, i.e. " venuS" => " VenuS")
  • Replace: $1\u$2
  1. Uncapitalize words
  • Find: (\s)([A-Z])
  • Replace: $1\l$2
  1. Remove a single camel case (e.g. cAmelCAse => camelcAse => camelcase)
  • Find: ([a-z])([A-Z])
  • Replace: $1\l$2
  1. Lowercase all from an uppercase letter within words (e.g. LowerCASe => Lowercase)
  • Find: (\w)([A-Z]+)
  • Replace: $1\L$2
  • Alternate Replace: \L$0
  1. Uppercase all from a lowercase letter within words (e.g. upperCASe => uPPERCASE)
  • Find: (\w)([A-Z]+)
  • Replace: $1\U$2
  1. Uppercase previous (e.g. upperCase => UPPERCase)
  • Find: (\w+)([A-Z])
  • Replace: \U$1$2
  1. Lowercase previous (e.g. LOWERCase => lowerCase)
  • Find: (\w+)([A-Z])
  • Replace: \L$1$2
  1. Uppercase the rest (e.g. upperCase => upperCASE)
  • Find: ([A-Z])(\w+)
  • Replace: $1\U$2
  1. Lowercase the rest (e.g. lOWERCASE => lOwercase)
  • Find: ([A-Z])(\w+)
  • Replace: $1\L$2
  1. Shift-right-uppercase (e.g. Case => cAse => caSe => casE)
  • Find: ([a-z\s])([A-Z])(\w)
  • Replace: $1\l$2\u$3
  1. Shift-left-uppercase (e.g. CasE => CaSe => CAse => Case)
  • Find: (\w)([A-Z])([a-z\s])
  • Replace: \u$1\l$2$3
1
  • 2
    What a wonderful thing! This answer is the best! Reminds me of DreamWeaver 8 where I would revamp entire sites with regex - especially bloated MS stuff. Anyway, this was super useful in scripting DB2-to-(lowercase)Postgres SQL change-over. Nov 16, 2020 at 14:22
9

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. enter image description here

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.