代码之家  ›  专栏  ›  技术社区  ›  y0mbo

替换Visual Studio代码段文字中的文本

  •  1
  • y0mbo  · 技术社区  · 15 年前

    在按下enter键且代码段退出编辑模式后,是否可以替换Visual Studio代码段文字中的文本?

     public void $name$
     {
       $end$
     }
    

     My function name
    

    是否可以让Visual Studio将其更改为:

     My_function_name
    

     MyFunctionName
    
    0 回复  |  直到 15 年前
        1
  •  5
  •   MincedMeatMole    5 年前

    "Replace Whitespaces": {
        "prefix": "wrap2",
        "body": [
            "${TM_SELECTED_TEXT/[' ']/_/gi}",
        ],
        "description": "Replace all whitespaces of highlighted Text with underscores"
    },
    

    将其添加到用户代码段中。或者,您也可以添加如下键盘快捷键:

    {
        "key": "ctrl+shift+y",
        "command": "editor.action.insertSnippet",
        "when": "editorTextFocus",
        "args": {
            "snippet": "${TM_SELECTED_TEXT/[' ']/_/gi}"            
        }
    },
    

    希望这有助于任何人在未来遇到这一点

        2
  •  0
  •   BPH    4 年前

    TM_SELECTED_TEXT - this is the input
    [ ' '] - regex find
    _ - regex replace
    gi - global flag for regex
    

    所以我想要的是改变: "User logged in" 进入: <%= gettext("User logged in") %> 对于我使用的代码段中的这一点:

    "body": ["<%= gettext(\"${TM_SELECTED_TEXT/['\"']//gi}\") %>"],