某些位置的代码段变量转换 [英] Snippet variable transform in some locations
问题描述
例如:
export const setVisibilityFilter = (filter) => ({
type: 'SET_VISIBILITY_FILTER',
filter
})
函数 setVisibilityFilter
的名称带有camelCase。在书面版本中,下划线大写字符相同: SET_VISIBILITY_FILTER
The name of the function setVisibilityFilter
has camelCase. The same in the written version in uppercase characters separated by underscores: SET_VISIBILITY_FILTER
我要制作一个摘录它。我希望在snippet变量中输入任何文本之后,第二个位置是用该文本创建由下划线分隔的大写字符。
I want to make a snippet out of it. I want that after entering any text in the snippet variable, in the second place the uppercase characters separated by underscores were created from this text.
这样,我不必第二次写,只能用大写字母写...
So that I do not have to write it for the second time, only in large letters ...
是否有可能在摘要中以及如何做到?
Is it possible in a snippet and how to do it?
推荐答案
vscode 1.25确实在代码段制表符上添加了转换,因此无需预先选择。此版本有效,并且可以使用任意数量的camelCase单词,例如 camelCase
, camelCaseCaseCase
等。
vscode 1.25 did add transforms on snippet tabstops, so no need for a pre-selection. This version works, and with any number of camelCase words, like "camelCase
", "camelCaseCaseCase
", etc.
"test3": {
"prefix": "seps",
"body": [
"export const $1 = (filter) => ({",
"type: '${1/([a-z]*)(([A-Z])+([a-z]+))?/${1:/upcase}${2:+_}$3${4:/upcase}/g}',",
"filter",
"})"
],
"description": "underscore separators"
}
请参见我的类似答案从camelCase转换为所有CAPS_WITH_SEPARATORS
这篇关于某些位置的代码段变量转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!