How to do multiple line editing?
EclipseLineEclipse Problem Overview
I want to edit multiple lines in eclipse, but I can't find any short cut or Plugin. In Geany I just press ctrl+alt+up/down I can add / edit multiple lines.
Maybe this example can explain what I mean:
var text = "myname";
var addr = "myaddr";
var age = "myage";
I want to edit text above into:
var my_text = "myname";
var my_addr = "myaddr";
var my_age = "myage";
The text above is just a simple example, but sometimes I have many lines of words that I have to edit its prefix.
Eclipse Solutions
Solution 1 - Eclipse
Press alt + shift + A to Toggle block selection (Toggle block / column selection in the current text editor), this will let you write vertically in eclipse, then you can easily do this.
Go to Window->Preferences.
Find for binding in text box surrounded by red box.
Solution 2 - Eclipse
On OS X, the key combination for multi-line edits in Eclipse (or STS) is option/alt+command+A
Solution 3 - Eclipse
You can try the following plugin,
https://github.com/caspark/eclipse-multicursor/releases
With this multiple occurrence of same text can be selected and edited. This is similar to multi select functionality available in editors like Sublime and Visual studio code.
Solution 4 - Eclipse
The Eclipse 4.22 (Q4 2021) equivalent of Geany would Alt+Click on the lines you want to edit in one go.
Eclipse now supports
> ## Multiple text selection
>
> Support for multiple selection has been added to Text Editors.
>
> Multi selections allow most edit operations (text replacement or insertion, extend selection to next word or to next line, copy/paste...) to apply simultaneously on all ranges.
>
>
>
>Multiple strategies are available to enable multi-selections:
>
> - Turn a block selection into a multi-selection using the To multi-selection command,
> - Add a caret with Alt+Click,
> - Use the new Select All
button on the Find/Replace
dialog.
So check if this would work in your case.
Solution 5 - Eclipse
The Eclipse 4.24 (June 15 2022) will integrate it (See https://bugs.eclipse.org/bugs/show_bug.cgi?id=576377):
- Multi selection down relative to anchor selection (e.g. Ctrl-Alt-J)
- Multi selection up relative to anchor selection (e.g. Alt-J)
- End multi-selection (e.g. ESC)
- Add all matches to multi-selection (e.g. Ctrl-Shift-Alt-J)
- Multi caret up (e.g. Ctrl-Alt-Shift-Up)
- Multi caret down (e.g. Ctrl-Alt-Shift-Down)
Thanks to eclipse contributor !