首页 > 解决方案 > 如何使用选定的行在当前打开的文件夹中搜索

问题描述

我正在使用 vscode。如何通过键盘快捷键workbench.view.search使用选定的行 ( ) 在当前打开的文件夹中搜索 ( )。expandLineSelection

标签: visual-studio-code

解决方案


使用我写的扩展Find and Transform和这个键绑定:

{
  "key": "alt+z",                // whatever keybinding you want
  "command": "runInSearchPanel",
  "args": {
    "isRegex": false,
    "triggerSearch": true,
    "filesToInclude": "${relativeFileDirname}",  // many other path variables as well

    // all the other search options are available, like 'matchCase',
    // 'find', 'replace, etc.
  }
}

将在当前文件的父目录中搜索任何选择。如果您未指定查找查询,则选择将用作查询。

您可以将其与宏扩展名放在一起,在这里使用multi-command,如下所示:

{
  "key": "alt+z",
  "command": "extension.multiCommand.execute",
  "args": {
    "sequence": [
      "expandLineSelection",
      "cursorLeftSelect",  // to get rid of the trailing newline
      {
        "command": "runInSearchPanel",
        "args": {
          "isRegex": false,
          "triggerSearch": true,
          "filesToInclude": "${relativeFileDirname}"
        }
      }
    ]
  },
  "when": "editorTextFocus"
}

搜索线扩展宏

[我看到这expandLineSelection包括尾随的换行符。但这似乎不影响结果。无论如何,我添加"cursorLeftSelect"到上面的宏以摆脱尾随的换行符。]


推荐阅读