繁体   English   中英

在 VScode 中使用多个光标进行搜索

[英]Search with multiple cursors in VScode

注意:这不是在 VSCode 中选择所有出现的选定单词”的副本

我已经有多个游标。 想象一下| 是游标,我有 3 个这样的

Some Line|Some Text, More Text
Some Other Line|Some Other Text, Other More Text
Yet Another Line|Yet Some Other Text, Yet Other More Text

现在我想将所有 3 个光标移动到,在它们各自的行中。 理想情况下,我希望能够使用完整的搜索来执行此操作,因为搜索通常需要更多细微差别(例如第一个逗号后跟以 T 开头的单词)。 这是我通常会在其他编辑器中使用键盘宏解决的问题,但 VSCode 没有这些,我被告知多个光标是解决方案,但我还没有找到搜索所有光标的方法

您可以使用扩展名Select By和命令moveby.regex

您可以将其设置为使用固定的正则表达式来搜索或要求您提供正则表达式:

{
    "key": "ctrl+shift+f6",  // or any other key combo
    "when": "editorTextFocus",
    "command": "moveby.regex",
    "args": {
      "ask": true,
      "properties": ["next", "start"]
    }
  }

你可以使用这个扩展, 查找和转换(免责声明:我是作者)来做你想做的事。 示例键绑定:


{
  "key": "alt+f",
  "command": "findInCurrentFile",
  "args": {

    "find": ",(?=\\s*T)",  // the first , followed by a word with a T

    // "replace": "***",

    "isRegex": true,
    "matchCase": true

    // if you want to fine-tuen where the cursor ends up, use postCommands
    // "postCommands": ["cursorLeft", "cursorRight"]

  },
},

它适用于多个光标.... 演示:

使用多个游标演示转到文档中的下一个正则表达式

尽管您可能会发现使用此键绑定更容易使用替换或选择来循环匹配(使用单个光标):

{
  "key": "alt+f",
  "command": "findInCurrentFile",
  "args": {

    "find": ",(?=\\s*T)",
    // "replace": "***",

    "isRegex": true,
    "matchCase": true,

    // "restrictFind": "line"
    "restrictFind": "nextMoveCursor",

    // "postCommands": ["cursorLeft", "cursorRight"]
  },
},

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM