【问题标题】:Visual Studio Code Find/replace - save with nameVisual Studio 代码查找/替换 - 使用名称保存
【发布时间】:2018-04-20 14:06:09
【问题描述】:

我经常发现在 Visual Studio 代码中需要一些自定义正则表达式。

每次我使用 stackoverflow 搜索来查找相同的正则表达式,而不是一次又一次地重写它。现在我有一个单独的文本注释,仅用于该目的,其中包含我的查找/替换正则表达式值。 例如remove duplicates

是否有自定义智能插件或选项允许我在 Visual Studio Code 中直接添加查找/替换并为其命名并保存(类似于超级编辑)?

如果有一种方法可以在 Visual Studio 中而不是代码中执行相同的操作,我也可以使用它 - 我只需要能够快速查找替换。

【问题讨论】:

    标签: regex visual-studio visual-studio-code find-replace


    【解决方案1】:

    至少有三个扩展可以帮助你:

    Find and Transform - 我写的

    replace rules

    regreplace

    它们允许您存储和运行(单独或全部保存)正则表达式的查找和替换列表。

    查找和替换的示例设置(settings.json):

    "findInCurrentFile": { 
    
      "addClassToElement": {
        "title": "Add Class to Html Element",   // will appear in the Command Palette
        "find": ">",
        "replace": " class=\"@\">",
        "restrictFind": "selections",
        "cursorMoveSelect": "@"   // after the replacement, move to and select this text
      }
    }
    

    查找和替换中的键绑定示例(在 keybindings.json 中):

    {
      "key": "alt+y",
      "command": "findInCurrentFile",     // note no setting command here
      "args": {
        
        "find": "^([ \\t]*const\\s*)(\\w*)",   // note the double escaping
        
        "replace": "$1\\U$2",                  // capitalize the word following "const"
        "isRegex": true,
        
        "restrictFind": "selections"           // find only in selections
      }
    }
    

    因此,您可以将查找/替换或跨文件搜索保存为命名设置或键绑定。

    【讨论】:

      猜你喜欢
      • 2016-07-04
      • 2016-10-03
      • 2011-08-23
      • 1970-01-01
      • 2010-09-26
      • 2010-10-23
      • 1970-01-01
      • 1970-01-01
      • 2015-09-06
      相关资源
      最近更新 更多