VS Code:如何将片段占位符转换为大写或小写? [英] VS Code: How to convert snippet placeholder to uppercase or lowercase?

查看:39
本文介绍了VS Code:如何将片段占位符转换为大写或小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 VS Code 中,用于创建用户定义代码段的文档提到了一些Grammar 包括 /upcase/downcase 的选项/capitalize,但我不知道如何使用它.

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.

我在 Mac 上使用最新版本的 VS Code:Version 1.25.0.

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

似乎这个代码段应该在输入并点击 tab 后将占位符的值转换为大写和小写,但它没有:

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}"
},

流程和预期结果

  1. 输入 test
  2. 点击 tab 获取代码片段.
  3. 输入 Asdf 得到:

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

Asdf -> Asdf Asdf

  • 点击 tab 以获得预期结果:

    Asdf -> ASDF asdf
    

  • 当前结果

    asdf -> asdf asdf
    

    推荐答案

    试试这个:

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

    您需要点击 Tab 来应用转换.

    You need to hit Tab to apply the transformation.

    这篇关于VS Code:如何将片段占位符转换为大写或小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆