簡體   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