intellij-ideacopy-pastecode-editor

Replacing automatically-highlighted code across several lines in IntelliJ


IntelliJ has a feature where (a) you select part of one line, then (b) IntelliJ immediately and automatically highlights that same text that happens to exist is multiple lines of similar code in that same file.

Given that IntelliJ has identified that duplicated text, is there a way to simultaneously type-over or paste-over the duplicated text across all those lines?

Seems silly for IntelliJ to show me all the duplication but then make me copy-paste-paste-paste-paste-paste across each line.


Solution

  • You can use Select All Occurrences (⌘⌃G on macOS, or Ctrl+Alt+Shift+J on Windows/Linux).

    After the selection is complete, you can start editing all the fragments as if they were all the same one. See this example in the Guide.


    Alternatively, you can also use Rename refactorings to change names of symbols, files, directories, packages, modules and all the references to them throughout code. To do so, select the name you want to refactor and use the shortcut Shift F6.