skip to Main Content

In VS Code, I can press Ctrl+D, multiple times, with a word selected inside a file and it will select all the occurrences of that same word in a multi-cursor fashion, which is great.

Now, I want to do the same, but over multiple files. If I use the "search" tool in the left menu, I can easily select all the occurrences where I would like to change, over multiple files. There is a "Replace with" option, but my case is not just replacing text with the same text. I would need to copy something from each line and place it again on the same line — as you can easily do with multi-cursor selection.

So I would like to combine both things: multi-cursor selection, but among multiple files. So a multi-file-multi-cursor selection, lets say.

Is that possible?

2

Answers


  1. Yes, you press "Open new search editor" above the search bar (or in Ctrl+Shift+P) and search for your string there.

    The search results are presented as if they were a bit text file, and multi-cursor works there.

    But probably manually grepping for the string is more convenient.

    Login or Signup to reply.
  2. but my case is not just replacing text with the same text. I would need to copy something from each line and place it again on the same line — as you can easily do with multi-cursor selection.

    Note that regex find and replace in the Search View is a thing. You can use regex grouping. Ex. If you want to replace <ignore> <some-alphas> <some-nums> <ignore> with <some-nums> <some-alphas>, you could turn on regex mode, search for ([a-zA-Z]+) ([0-9]+) and then put $2 $1 in the replace field, adjust the search details like include files / exclude files patthers, dismiss any finer-grained matches you don’t want to touch, and then replace all.


    As for the thing with occurrence selection, VS Code 1.85 just added multi-document occurrence highlighting: https://code.visualstudio.com/updates/v1_84#_multidocument-highlighting (just visual highlighting and not actual text selection / cursor creation) (see the setting editor.multiDocumentOccurrencesHighlight which defaults to false in v1.85). So it doesn’t seem like a big stretch for them to also implement actual text selection of occurrences across documents / editors. If you’d like for that to be a thing, I’d suggest to raise an issue ticket. If you do, please comment here with a link to your issue ticket or edit the link into this answer post.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search