I'm using Visual Studio Code 1.14.2, and I'm trying to change name of variables to camelCase eg.
set_nominal_wavelength to setNominalWavelength.
Regular expression: _([a-z])
Replace: \U1ドル\E
does not work. Any idea how to achieve it?
3 Answers 3
As of vscode v1.75 there is a Transform to Camel Case command. So you could
- Find:
(_[a-z]+)+ Alt+Enterwill select all those- trigger the
Transform to Camel Casecommand
Pretty easy.
In the 1.47 Insiders Build support for the replace case modifiers (\L, \l, \U, \u) has been added to vscode. And so should be in the 1.47 stable release).
So simply doing your find: _([a-z])
and replace with \u1ドル (since you only want to capitalize the first letter) works nicely in the Insiders Build now.
Works in both the Find Widget and the Search Panel.
10 Comments
Toggle Screencast Mode and for the gif I use screentogif.com which works well enough but sometimes gets confused by keystroke input. There are 2 vscode screencast settings to look at too: vertical offset and Only Keyboard Shortcuts (so just control keychords are shown not everything like text you might type).There is a workaround:
- Open Replace dialog and enter regex:
_([a-z]) - Then move focus to the editor area and press Ctrl+F2 ("Change All Occurrences")
- Then change case of selection (Ctrl+P>upper)
- Then press Left Arrow key and press Delete key
5 Comments
You may use other tools that support change case operators, like Notepad++, sed, R (gsub with perl=TRUE), but VS Code does not support these operators in the replacement pattern.
See this feature request on GitHub:
This is cool to have. This is beyond the scope of what is currently supported by javascript.
We need to come up with our own advanced replace engine to support these cases.
sedin terminal. Just been curious if it's possible in VScode.