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

问题描述 投票:2回答:1

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

例如,给出如下代码段:

 public void $name$
 {
   $end$
 }

如果输入$ name $为:

 My function name

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

 My_function_name

 MyFunctionName
visual-studio code-snippets
1个回答
0
投票

多年后,对于仍然遇到此问题的任何人,都有一个答案:

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

希望这可以帮助将来遇到此问题的任何人

© www.soinside.com 2019 - 2024. All rights reserved.