Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capitalize first letter of VSCode snippet

I want to create VSCode snippet to quickly use React's useState. E.g. for a state open

const [open, setOpen] = useState()

I'm currently using

"const [ ${1}, set$1 ] = useState()"

But this gives me const [open, setopen] = useState(). Note the lack of caps on open.

I want to be able to just enter the state name open, and have the snippet sort out the capitalization for setOpen. I know I could use 2 variables, but I don't want to type it out twice since it'll always follow the pattern [foo, setFoo]

I know I can do transforms like ${1:/upcase}, but this capitalizes the entire variable, not just the first letter.

like image 867
Henry Avatar asked Sep 13 '25 14:09

Henry


1 Answers

This should work:

"const [ ${1}, set${1/(.*)/${1:/capitalize}/} ] = useState()"
like image 64
Guillermo Brachetta Avatar answered Sep 16 '25 09:09

Guillermo Brachetta