Skip to content

Instantly share code, notes, and snippets.

@R3V1Z3
Last active March 3, 2026 14:14
Show Gist options
  • Select an option

  • Save R3V1Z3/2a271f6440f1ac7e028df55e94035e40 to your computer and use it in GitHub Desktop.

Select an option

Save R3V1Z3/2a271f6440f1ac7e028df55e94035e40 to your computer and use it in GitHub Desktop.
Convert all occurrences of snake_case to camelCase in VS Code. Windows/Linux walk-through here: https://youtu.be/vlHel1fN5_A

Convert snake_case to camelCase in VS Code

  • Press CTRL-H ( ⌥⌘F on Mac ).
  • Press ALT-R ( ⌥⌘R on Mac ).
  • Type _([a-zA-Z]).
  • Press TAB and type $1.
  • Press ALT-ENTER ( ⌥ENTER on Mac ).
  • Press F1 and type upper, then press ENTER.
  • Press CTRL-ALT-ENTER ( ⌥ENTER on Mac ).

Explanation

VS Code (and Atom) currently use JavaScript-style regular expressions for the find/replace feature so the replace operation doesn't support switches that are available in other editors like Vim (example: \u\1) or Sublime Text (example: $1-\L$1\E).

The workflow above will achieve the same results.

@dev-techmoe
Copy link

fantastic!

@benny1213
Copy link

awsome

@2zqa
Copy link

2zqa commented Sep 16, 2024

This helped me:

search: _(.) (RegEx enabled)
replace: \U$1

@cormacconway
Copy link

If you add the following to your keybindings.json then this becomes a keyboard shortcut (ctrl+shift+k in this case)
To get to this file click ctrl+shift+p and type keyboard
select Open Keyboard Shortcut (JSON)

after the last curly bracket (}) in this file add a comma (,) so the last 2 lines of your file should look like this:

	},
]

to add a new keyboard shortcut paste the following after the comma you just added but before the square bracket (]):

{
        "key": "ctrl+shift+k",
        "command": "runCommands",
        "args": {
            "commands": [
                {
                "command" : "editor.actions.findWithArgs",
                "args": {
                    "searchString": "_([a-zA-Z])",
                    "replaceString": "$1",
                    "isRegex": true
                },
            },
            "editor.action.selectAllMatches",
            "editor.action.transformToUppercase",
            "editor.action.replaceAll"
            ]
        },
        "when": "editorTextFocus"
    }

Now when you press ctrl+shift+k in a file it will run the snake case to lowerCamelCase conversion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment