提问者:小点点

在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没有这些,我被告知多个光标是解决方案,但我还没有找到搜索所有光标的方法


共2个答案

匿名用户

您可以使用扩展选择和命令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"]
  },
},