Wednesday, March 30, 2011

One-click editor splitting in Eclipse

[Note: Does not work in Eclipse 4.x]
UPDATE: Eclipse Luna 4.4 M4 now supports editor splitting... NEW and NOTEWORTHY.

You may know that one can split layout the editors in Eclipse by dragging the editor tab to any edge of the editor area. This works only if you have more than one editor. However there are times when I want to work on two parts of the same file. To do that I first do Window > New Editor to duplicate the editor and then drag it to split the editor in a side-by-side or top-bottom layout. But that is too many clicks and drags. I developed a simple Eclipse Plugin which will help you split the active editor either horizontally or vertically with a single click. It is based on some code I found here that was written by Dimitri Missoh (thanks Dimitri - I have given you credit in the source code of the plug-in). I adapted his code to suite our purpose.

Here is the screenshot:


Split Editor Plug-in is available on Eclipse Marketplace!

You can install it from the plug-in's update site:

http://sandipchitaleseclipseplugins.googlecode.com/svn/trunk/SplitEditorFeatureUpdateSite

Source code is here.

Works in Eclipse 3.4, 3.5, 3.6, 3.7 and 3.8.

Also available on Eclipse Marketplace.

Enjoy!

17 comments:

Unknown said...

This functionality is also provided by the Emacs+ plugin, with the "split-window-horizontally" and "split-window-vertically" functions, which are easily bound to keys. The fact that it doesn't provide a mouse-clickable icon to do this is not missed by me at all.

Sandip Chitale said...

Thanks for that info David. It it possible to add key bindings to commands Split Editor provides also using the General > Keys preferences page. I did not add them by default to leave it to personal taste.

Anonymous said...

I real happy to find this internet site on bing, just what I was searching for : D likewise saved to my bookmarks .

Anonymous said...

nice plugin, very usable :-)

Anonymous said...

Is it possible to switch between horizontal and vertical?

Sandip Chitale said...

Yes. There are two toolbar button - one for horizontal split and one for vertical split.

Anonymous said...

I love this tiny-yet-usefull plugin. I have one comment though...
I've just installed SplitEditor version 1.0.5 on Eclipse 3.7.1 and I noticed it depends on 3.6 (so a lot of eclipse 3.6 was installed in the process). Is this really necessary?

Anonymous said...

I love this tiny-yet-usefull plugin. I have one comment though...
I've just installed SplitEditor version 1.0.5 on Eclipse 3.7.1 and I noticed it depends on 3.6 (so a lot of eclipse 3.6 was installed in the process). Is this really necessary?

Sandip Chitale said...

@Anonymous...can you tell me what you mean by a lot of "eclipse 3.6 was installed in the process". If you mean that you see some plugins are at version 3.6 that is normal. Eclipse folks increment the version numbers only when there is a change and hence some plugins may still be 3.6. Or are you saying that you actually saw it downloading older versions on the plugins?

skin27 said...

Nice enhancement. I miss only an "open with ..." under the arrow to open the same file with another editor (without right-clicking the file first)

Özcan Acar said...

Thank you. Saves me a lot of time dragging around.

Patrick said...

This great plug-in doesn't work in Eclipse Juno (4.2) any more :-( When I click on the split icon, I get the following Exception:

java.lang.NoClassDefFoundError: org/eclipse/ui/internal/PartStack
at spliteditor.Handler$1.partActivated(Handler.java:74)
at org.eclipse.ui.internal.WorkbenchPage$11.run(WorkbenchPage.java:4306)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.WorkbenchPage.firePartActivated(WorkbenchPage.java:4304)
at org.eclipse.ui.internal.WorkbenchPage.access$14(WorkbenchPage.java:4292)
at org.eclipse.ui.internal.WorkbenchPage$E4PartListener.partActivated(WorkbenchPage.java:169)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl$2.run(PartServiceImpl.java:190)
...

Sandip Chitale said...

@Patrick I have not tried the plug-in in Eclipse 4.2. The fact that it does not work is to be expected as they made lot of changes to the workbench code in 4.2. I filed an issue in the project page. You can track it here:

http://code.google.com/p/sandipchitaleseclipseplugins/issues/detail?id=7

PeterVermont said...

Gets an error withh Juno SR2 on MacOS.

By the way, please show dates in the comments -- I see only time so I don't know when the comments were made.

eclipse.buildId=M20120914-1800
java.version=1.6.0_43
java.vendor=Apple Inc.
BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
Framework arguments: -product org.eclipse.epp.package.java.product -keyring /Users/pandrews/.eclipse_keyring -showlocation
Command-line arguments: -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/pandrews/.eclipse_keyring -showlocation

Error
Sat Apr 13 13:50:14 EDT 2013
Problems occurred when invoking code from plug-in: "org.eclipse.ui.workbench".

java.lang.NoClassDefFoundError: org/eclipse/ui/internal/PartStack
at spliteditor.Handler$1.partActivated(Handler.java:64)
at org.eclipse.ui.internal.WorkbenchPage$11.run(WorkbenchPage.java:4319)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.WorkbenchPage.firePartActivated(WorkbenchPage.java:4317)

PeterVermont said...

Gets an error withh Juno SR2 on MacOS.

By the way, please show dates in the comments -- I see only time so I don't know when the comments were made.

eclipse.buildId=M20120914-1800
java.version=1.6.0_43
java.vendor=Apple Inc.
BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
Framework arguments: -product org.eclipse.epp.package.java.product -keyring /Users/pandrews/.eclipse_keyring -showlocation
Command-line arguments: -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/pandrews/.eclipse_keyring -showlocation

Error
Sat Apr 13 13:50:14 EDT 2013
Problems occurred when invoking code from plug-in: "org.eclipse.ui.workbench".

java.lang.NoClassDefFoundError: org/eclipse/ui/internal/PartStack
at spliteditor.Handler$1.partActivated(Handler.java:64)
at org.eclipse.ui.internal.WorkbenchPage$11.run(WorkbenchPage.java:4319)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.WorkbenchPage.firePartActivated(WorkbenchPage.java:4317)

Sandip Chitale said...

@PeterVermont This plug-in works on Eclipse 3.x only. The APIs for Workbench have changed a lot in 4.x. I will have to rewrite the plug-in for 4.x.

And the comment timestamp format is controlled by the blogger, I need to check if I can change it. I agree though that it should show the date also.

Sandip Chitale said...

@PeterVermont I have changed the settings to show full timestamp of comments.