VS Code: How to convert snippet placeholder to uppercase or lowercase?

对着背影说爱祢 提交于 2019-12-20 23:31:28

问题


In VS Code, the docs for creating user defined snippets mentions some Grammar which includes options for /upcase, /downcase, and /capitalize, but I can't figure out how to use it.

I'm using the latest version of VS Code: Version 1.25.0 on Mac.

It seems like this snippet should convert the value of the placeholder to uppercase and to lowercase after typing it and hitting tab, but it doesn’t:

"test": {
    "prefix": "test",
    "body": "${1} -> ${1:/upcase} ${1:/downcase}"
},

Flow and Expected Result

  1. type test
  2. hit tab to get the snippet.
  3. type Asdf to result in:

    Asdf -> Asdf Asdf
    
  4. hit tab to get expected result of:

    Asdf -> ASDF asdf
    

Current Result

asdf -> asdf asdf

回答1:


Try this:

"test": {
    "prefix": "test",
    // "body": "${1} -> ${1/(.*)/${1:/upcase}/} > ${1/(.*)/${1:/downcase}/}"
    // simpler version below works too
    "body": "${1} -> ${1/(.*)/${1:/upcase} ${1:/downcase}/}"
}

You need to hit Tab to apply the transformation.




回答2:


For reference:

The integer in the EBNF docs refers to a RegExp group not to a tabstop reference so should work:

"test": {
    "prefix": "test",
    "body": "${1} -> ${1/(Asdf)/${1:/upcase}/} ${1/(Asdf)/${1:/downcase}/}"
}


来源:https://stackoverflow.com/questions/51272365/vs-code-how-to-convert-snippet-placeholder-to-uppercase-or-lowercase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!