Skip to Content
Author's profile photo Michael Schneider

Block Selection Mode in Eclipse

Recently, I did some pair programming with one of my colleagues. My colleague showed me the block selection mode. This is a small feature provided by Eclipse which I would like to share with you, today.

I knew this feature for selecting and copying some blocks from my ABAP source code. You can compare it to the short-cut CTRL+Y in SAP GUI. I guess you know this one.

blockSelectionMode.png

This functionality on its own is already very helpful, but I didn’t know that you can use this mode also to edit source code in an Eclipse editor. Therefore, here is the whole story…

We were in the following situation: We wanted to write an ABAP Unit test that has to add some source code to an internal table that has to be processed by the test. We just copied the source code for the test in our test method.

blockSelectionInsert0.png

In the past, I changed the coding manually by going through each line and adding APPEND ‘ in the front and ‘ TO SOURCE_CODE. at the end of each line. Sometimes I created a small macro to save some time. But still than, I had to surround each source code line with the quote sign.

Block selection mode in Eclipse allowed us to make this change in a much easier way…

We just started block selection mode by using the short-cut Alt+Shift+A. Than we were able to select all lines in front of my source code as shown in the following screenshot.

blockSelectionInsert1.png

After that we added my APPEND ‘ in front of each source code line in one shot…

blockSelectionInsert2.png

… and did the same with ‘ TO SOURCE_CODE. at the end of each source code line.

blockSelectionInsert4.png

Done! In this situation this saved us a lot of time, because we had to do it not just for one test!

Maybe it will save you some time in the future, too!

P.S.: To disable block selection mode you just press the short-cut Alt+Shift+A, again.

Assigned Tags

      11 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      For those unaware, this is how to do it in New ABAP Editor.

      Method 1: Using regular expression and replace in selection.

      (.*) means select entire line, $1 in replace means insert the found text.

      Method 2: Block selection using ALT + MouseDrag

      Type append ' and use Ctrl+D to duplicate lines.

      Alt+MouseDrag to block select the text to be inserted.

      Drag the selected text to where it needs to be inserted (start of line 8).

      Author's profile photo Adriano S. Campanhola
      Adriano S. Campanhola

      I had to login just to say: Thank you! I always forget that the regular expression exists in the search feature, and when I do, I have a lot of trouble using it =)

      Author's profile photo Michael Schneider
      Michael Schneider
      Blog Post Author

      Hi Manish,

      Thanks for sharing! I just forgot this...

      This will help me when I have to fix something in old releases... 🙂

      Michael

      Author's profile photo Christian Guenter
      Christian Guenter

      Additon to Method 2:

      You can do this directly by marking lines via ALT + Shift + UP/Down and then typing append '.

      I think multiple cursors are one of the most useful and little-known features in the New ABAP Editor. Once you know it, it can really boost your productivity.

      Regards Christian

      Author's profile photo Former Member
      Former Member

      I am on SAP Logon 720. Which SAP GUI version are you using?

      Alt Mousedrag is same as Alt Shift up/down.

      When I type something after selecting multiple lines, it gets inserted only at first line of block, not all.

      Author's profile photo Adriano S. Campanhola
      Adriano S. Campanhola

      AFAIK(or remember) this was made avaiable on Sap Gui 7.30 Patch level 4

      Author's profile photo Christian Guenter
      Christian Guenter

      I'm on SAG Gui 7.30 Pl 8. Can't remember when it was introduced.

      Alt Mousedrag is same as Alt Shift up/down.

      Yes, of course. Key point is that you can type in multiple lines with this technique.

      Author's profile photo Gerald Roux
      Gerald Roux

      Nice one Michael, this is a feature I've missed a few times after moving to AiE.  Thanks for sharing 🙂

      Author's profile photo Oliver Jaegle
      Oliver Jaegle

      Thanks for sharing!

      I'm a huge fanboy of the hidden gems of the ABAP-editor and as such I got to love the ALT + Mousedrag a lot. Missing this feature in AiE hurt - up to now. Though in one aspect the AiE Editor behaves differently: I used the block selection particularly in order to align e. g. data-declarations for multiple rows. When using the TAB in AiE block selection this affects the whole line though (and not the block marked). Is there any setting I'm missing which changes this behaviour?

      Cheers,

      Oliver

      Author's profile photo Michael Schneider
      Michael Schneider
      Blog Post Author

      Hi Oliver,

      Unfortunately, this is not possible, currently.

      At least I found an improvement request for Eclipse regarding this issue:

      Bug 288430 [block selection] Shift Left/Right with Block Selection

      Michael

      Author's profile photo Joachim Rees
      Joachim Rees

      I knew this block-selection mode (Alt+Shift+A) yes, but after only asking internally - thanks @ Daniel!
      But I think it's a bit 'clunky' in AdT - in the use case you describe, I'd probably still copy the source overt to notepad++, do the editing there and the copy it back.

      The block mode in notepad++ it's just:
      alt+mouse(clic+hold+drag)
      or
      alt+shift+arrow-keys.

      -> With this 'hack', I especially like being able to do it without a mouse, #keyboardOnly.

      best
      Joachim