Split and view the same editor side by side in Eclipse

At some point you’ll want to view the same class or file side by side. You may want to follow related code in different parts of the class or need some code constantly available as reference to change some other part of the class.

Eclipse allows you to split an editor and move it to anywhere in the editor area in the same window, including next to the original editor. Changes made in the one editor are reflected in the other. The feature isn’t very obviously named, but it is easy to use.

How to view the same editor side by side

To get the same editor side by side, select Window > New Editor and then drag the new editor next to the original one.

As an example, watch the video below to see how to split the editor and move it next to the original.

Notes:

  • It may help to maximise the original editor first (Ctrl+M) to gain some screen space. You can then move the 2nd editor next to, above or below the original editor.
  • It’s not that clear that you can drag the editor next to the other one, so watch the video carefully for the outline that indicates when you can drop the other editor. It’s not that easy to get it right the first time, but play around with the different positions to see what works for you.
  • Changes made in one editor will reflect in the other one, but scrolling is (fortunately) independent.

Some keyboard shortcuts to help with this feature

Once you’ve got the editors side by side you may want to switch between them without having to use the mouse. To do this, press Ctrl+F6 once. This will switch between the last two active editors. In general, Ctrl+F6 cycles through all open editors, in order of the most recently active editor.

Tip: I’d also recommend mapping Ctrl+F6 to Ctrl+Tab by adding a mapping for the key Next Editor under Window > Preferences > General > Keys. It works a lot better than Ctrl+F6 since you can press the key without lifting your hands.

If you use often split editors, you may want to use the keyboard to split editors without using the mouse to activate the menu option. Here are two ways to do this:

  • Go to Window > Preferences > General > Keys. Search for the key New Editor and enter any keystroke you’d like to use (eg. Alt+Shift+B, E). Recommended
  • Alternatively, just press Alt+W, E. This uses the menu mnemonics to activate the New Editor menu option without having to remap any keys. This may not work if you have a plugin that registered another command under the Window menu with the mnemonic E or if mnemonics are affected by your OS settings. This should work most of the time, but for these reasons, the first method is recommended.

Related Tips

Share this tip

Support Eclipse On E

23 thoughts on “Split and view the same editor side by side in Eclipse

  1. That’s a nice solution, but still very cumbersome when you are used to EMACS’s C-x 2 (or 3).

    Is there a fast way to switch between the two editors with a key-combo?

    • Thanks, OcasoProtal. I haven’t used the EMACS commands you mention, so I’ll assume you’re looking for a key to create the new editor without choosing the menu option.

      You can map the New Editor command to a key combo under Window > Preferences > General > Keys. Search for New Editor and map the key to anything you like. Alternatively, just press Alt+W, E to invoke the menu command with menu mnemonics.

      To switch between the 2 editors, use Ctrl+F6. I would recommend mapping this additionally to Ctrl+Tab (under Keys, the name is Next Editor). Copy the command and map it to Ctrl+Tab. It works better than Ctrl+F6.

      I’ve got a post planned on editor navigation where I’ll discuss some of these points, but I’ll try and add them to this post as they are relevant. Thank you for raising them.

      Let me know how it goes.

  2. Thanks for making this tutorial; the key mappings are especially helpful!

    I made a split-view, but any new tabs I generate (e.g. by opening a file) end up on one side or the other. Do I need to repeat this process for each file, or is there some way to automatically make new tabs launch in both editors?

    • Thanks Matthew. Unfortunately, I suspect you’ll have to repeat the process for each new editor. I haven’t seen a way of telling Eclipse to open up editors automatically in split mode, but maybe someone who has will reply to this.

  3. Regarding @OscasoProtal’s post, c-x 3 in emacs will open up a new editor *and* split the window all at once, which means that you don’t have to drag and drop the second window to have them side by side. Do you know if eclipse is capable of doing this?

    • Taras, by default Eclipse doesn’t support this. However, you can do this by installing the Emacs+ plugin that was suggested to me by someone while discussing another tip.

      I don’t use Emacs+ personally, but have tried out this feature and it works quite well.

      Once you’ve installed the plugin, you can just press Ctrl+X, 2 or 3 depending on whether you want to split it horizontally or vertically. Remember to first either (a) configure your key binding to the Emacs+ Scheme (as explained in their installation instructions) or (b) configure the keys manually using the keyboard shortcut tip I posted some time ago, using the command keys described on the Emacs+ homepage to configure the keys. I’d recommend option (b), ie. only configuring the ones you’re interested in first, unless you feel comfortable enough using the Emacs+ Scheme from the outset.

      BTW, it has a lot of other Emacs features that you can use directly in Eclipse, so have a look at the homepage for other features.

      Let me know how this works for you.

    • Thanks for the heads up, Alex, and good luck with the plugin. I haven’t tried it myself but I’ll give it a go when I have some time and report back.

  4. Hi,

    I’ll be glad if you can help. What I want is to separete my perspectives by code and other stuffs. Example, in my Coding Perspective I want to see only views that help me coding, like outline, javadoc, markes, search, etc.

    In my Others Stuffs Perspective I want to see the views console, servers, and project explorer. Only.

    My problem is that I cannot close the Editor Area View from my Others Stuffs Perspective. I can minimize it but if I click in something that brings me to the source code my eclipse doesn’t leave me to my Coding Perspective, it opens my current View Editor Area.

    Do have any idea what can I do about it ?

    • Just to confirm: Are you struggling with the fact that you can’t link editors to a specific perspective only so you want editors to *always* open in the Coding Perspective but not in the Other Stuff perspective, even if you open an editor from the Other Stuff perspective?

      mmmm… I don’t think there’s a clean way around this in Eclipse but here’s a (dirty) idea using detached views (apologies if you already know about this feature):

      If you have multiple monitors, you could try detaching the views that would go in the Other Stuffs perspective and moving them to the next monitor. You can detach views by right-clicking on the view’s tab and choosing Detached which will make the view a floating view that you can move around.

      That way you could have your Console and Servers view on the one side and any editors you open will open in the Coding Perspective’s editor area. It’s not ideal though as you don’t get the advantages of having them nicely grouped in a different perspective and you need multiple monitors to work effectively.

      Note that in this arrangement, you only have one perspective (the Coding Perspective) but the other views are “out of the way” on the next monitor. And you can restore the detached view to the window by right-clicking its tab again and deselecting Detached.

      I can’t really think of another clean solution but if inspiration strikes I’ll let you know. Hope this helps.

  5. I’m running Eclipse 3.7.2.

    One thing is a major problem for me when using “split editors”. You write that “Changes made in one editor will reflect in the other one” – that is not the case for me. Say I have a left and a right editor, for the same file, changes in the left won’t update in the right – not until I save the left. When I save the left, the right is updated from disk – this could still be acceptable – but the problem is that when updating from disc, the scroll position of the right editor is set to where I made the change in the left file.

    Often when editing I’m reading code from the right editor at one position in the file, editing in the left editor at another position in the file. Every time I save changes in the left editor, I lose track of the scroll position in the right. Any idea how to fix this?

    • Sorry for the late reply. I haven’t seen that behaviour before – I use 3.7.2 on a Windows machine and it works as expected, ie. as I change the left side, the right side updates as well, even without saving.

      I’d suggest trying a fresh install on another machine (or the same one) to see if it isn’t due to some plugin that you’ve got installed (you can unzip and run Eclipse from another folder to avoid having to replace your existing installation).

      Unfortunately I haven’t found any obvious bug related to this so it might just be something with the particular setup you have. Sorry I couldn’t help more and please let me know how when you’ve solved it.

    • OK, thanks for your reply anyway. I’m using a plugin called Sigasi, maybe that’s what’s causing the problems.

  6. I tried switching between windows using Ctrl-F6, but instead of switching between the two files that I’ve currently got visible I get a dialog box labelled “Editors” in the middle of the screen, listing my open documents. As soon as I release the Ctrl key the dialog box goes away (before I’m able to choose which one I want). If I hold the Ctrl key down I can select one of them with the mouse, but that defeats the purpose of using a keystroke to switch windows.

    I’d love to figure this out – switching windows with a keystroke (Ctrl-TAB, to be specific) is one of the things I miss about xemacs.

    • It should normally just work if you press Ctrl+F6 and then release it. This should move to the last active editor.

      It sounds like you might have the preference on that keeps the list of editors open once you’ve pressed Ctrl+F6. Go to Window > Preferences > General and make sure “Keep next/previous editor, view and perspective dialog open” is unchecked.

      To map Ctrl+Tab to switch editors, go to Window > Preferences > General > Keys and assign the key for the command Next Editor. Also, have a look at How to manage keyboard shortcuts in Eclipse and why you should and Quick ways to navigate Eclipse editors using the keyboard.

    • That field was unchecked; checking it made the dialog box persist long enough to be used. Thanks!

      “Next Editor” was already associated with Ctrl-F6. What I’m looking for is something that bounces me back & forth between whatever editors are visible (not just those that have been opened, but where the contents are visible).

    • Ah yes, thanks for that Levan. I’ll update the post to mention that the instructions are for pre-4.4. I haven’t tried out the new features yet but I’ll try and do a post on it at some point.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>