Search code examples
visual-studio-codeidejetbrains-ide

Find and Append feature in JetBrains/VSCode


Is there some way to append something to a search result in JetBrains IDEs or VSCode?

Usually I'd use find and replace and just copy the old result and append things but now I am using regex search over multiple files and I need to add a line to all the results.

Usually using find and replace you'll get something like this: Find and replace

So instead of replacing the search result I want my input to be added the search result. Find and add This should be useful when using RegEx to edit multiple lines that have things in common.
In my case I was looking to add a field to all my enums that are like:

public enum EnumName {
   // field1
   // field2...
}

To be like :

public enum EnumName {
   // default field
   // field1
   // field2...
}

Solution

  • Thanks to @LazyOne replies, I've been able to find a way to do what I am looking for by using RegEx Capturing Groups that works in JetBrains IDEs (Intellij help) and VSCode too.
    It consists on putting the regular expression we want to add something to in parenthesis in the search field and then in the replace field using $1 $2.. to reference the RegExs given the actual order in the search.
    In my case using Jetbrains Rider I was looking to add something to all the enums in my solution, and I simply put my RegEx inside () so it became (.* enum .* .*\{) and then used $1 to reference it like this: Find and append using RegEx