Skip to content

Instantly share code, notes, and snippets.

@R3V1Z3
Last active April 16, 2024 09:18
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save R3V1Z3/2a271f6440f1ac7e028df55e94035e40 to your computer and use it in GitHub Desktop.
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.

@SpirosKar
Copy link

SpirosKar commented Sep 6, 2018

When I press ALT-R it request second key or chord. Do you forget to add it or I do something wrong.
Thanks in advance

@R3V1Z3
Copy link
Author

R3V1Z3 commented Sep 22, 2018

@SpirosKar, apologies for any confusion. I suspect you're on a Mac? The ALT-R keypress is for Windows and Linux, it just toggles the Regex option. You could simply select the Regex option with your mouse if it's easier.

I've also just updated the key-presses for Mac users. The key-based workflow has been tested on Windows and Linux where it works just fine. I don't have a Mac to test but the commands technically should work.

@ps2goat
Copy link

ps2goat commented Nov 13, 2018

I'm on Windows, and ALT-R doesn't work for me. I did not remap that key combination. When hovering, it doesn't have a pre-defined key combination like the match case and match whole word options do.

But thanks for the overall flow.

@R3V1Z3
Copy link
Author

R3V1Z3 commented Jan 2, 2019

Hmm, the purpose of ALT-R is to simply switch to regex mode. I've tested once again on Win10 (I usually use Kubuntu) and it works fine on my end, no other keypress configuration.

The keypress doesn't produce any outstanding visuals, it only selects the regex option in the Find/Replace dialog.

@msmikesm
Copy link

You made my day!
My case is the conversion of country codes into lowercase ^^
F: ([A-Z{2,}])
R: $1
F1

lower
CTRL+ALT+ENTER

@roycetech
Copy link

A simpler approach for me is to

  1. search with regex pattern _ [a-z]
  2. Do a "find all" (multi-cursor), option + enter on Mac OS
  3. Delete the underscores
  4. Select the letter and change to upper case using the command palette.

@dev-techmoe
Copy link

fantastic!

@benny1213
Copy link

awsome

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