Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capitalize one instance of a variable in a live template?

I am trying to make a template for React useState:

const [item, setItem] = useState('value')

const [$state$, set$state$] = useState($init$);$end$

Since item is the same, only with a capital I, is it possible to auto-capitalize the first letter?

I am doing it in VS Code like this:

const [$1, set${1/(.*)/${1:/capitalize}/}] = useState($2)
like image 236
ilyo Avatar asked Apr 27 '20 18:04

ilyo


People also ask

How do I add a variable to a template?

Choose Template > New Variable from the editor toolbar (or choose an existing variable to add it to the page) Enter a name for the variable. Press Enter (by default this will create a single-line text input field)

How do I use live Webstorm templates?

To configure live templates, open the Editor | Live Templates page of the IDE settings Ctrl+Alt+S . On the Live Templates page, you can see all the available live templates, edit them and create new templates. To make finding and editing templates easier, they are split into groups.

What is live template in Android Studio?

One of my favorite tools in Android Studio (AS) is “Live Templates”. It is a way to create simple code templates that can be accessed via auto-complete shortcuts. Using them is a productivity booster, since they will automate a lot of boilerplate code for you.


1 Answers

Create a second variable whose value depends on the first one.

For example, $state_ has its value initialized to capitalize(state) in the edit variables dialog

const [item, setItem] = useState('value')

const [$state$, set$state_$] = useState($init$);$end$

enter image description here

like image 92
Juan Mendes Avatar answered Oct 13 '22 13:10

Juan Mendes