0

Note: This is NOT a duplicate of "Select all occurrences of selected word in VSCode

I already have multiple cursors. Imagine | are the cursors and I have 3 like this

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 

Now I want to move all 3 cursors to the , in their respective lines. Ideally I'd like to be able to use a full search to do it as often the search would require more nuance (like first comma that's followed by word that starts with T). This is a problem I would generally solve with keyboard macros in other editors but VSCode doesn't have those and I'm told multiple cursors is the solution yet I have not found a way to do a search for all the cursors

2 Answers 2

1

You can use extension Select By and command moveby.regex

You can set it to use a fixed regex to search for or ask you for the regex:

{ "key": "ctrl+shift+f6", // or any other key combo "when": "editorTextFocus", "command": "moveby.regex", "args": { "ask": true, "properties": ["next", "start"] } } 
Sign up to request clarification or add additional context in comments.

Comments

1

You can use this extension, Find and Transform (disclaimer: I am the author) to do what you want. Sample keybinding:

 { "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"] }, }, 

It works with multiple cursors.... Demo:

go to next regex in document with multiple cursors demo

Although you might find it easier to use this keybinding instead to cycle through the matches with replace or selection instead (with a single cursor):

{ "key": "alt+f", "command": "findInCurrentFile", "args": { "find": ",(?=\\s*T)", // "replace": "***", "isRegex": true, "matchCase": true, // "restrictFind": "line" "restrictFind": "nextMoveCursor", // "postCommands": ["cursorLeft", "cursorRight"] }, }, 

Comments