40

I would like to quickly swap two views from one side to the other and wonder if there is a hotkey for this functionality?

RLH
  • 15,230
  • 22
  • 98
  • 182
pdenlinger
  • 3,897
  • 10
  • 60
  • 92
  • 1
    +1. FWIW, The current fastest way to get the file open in the assistant editor into the primary editor that I know of is to *Right Click in Assistant Editor > Open in Primary Editor* and the press +Return. But yeah, a keyboard shortcut for the swap will be real handy. – Manav Sep 18 '12 at 04:35
  • This would be very helpful when setting the assistant editor to Callers – funroll Jun 11 '13 at 16:21
  • Finally found one that works (answer below). It requires you to navigate to the symbol (e.g. using emacs keyboard shortcuts). Once you're there, it's quite fast and easy. – funroll Jun 12 '13 at 02:17

5 Answers5

31

Single Assistant Editor

This can be done in two steps. You can start with the cursor in either the Primary or the Assistant editor.

Step 1:

, - Open in Assistant / Primary Editor

It opens the current file (where the cursor is) in Primary Editor if you are in Assistant Editor and vice versa. You end up with two exact same files open.

Step 2:

^` - Move Focus to Next Editor (available since Xcode 8, in older version use J)

^ - Go Back (and open the result) in Primary / Assistant Editor

This opens the previous file of the other editor in the first one.

Idea: It might be even possible to assign a custom shortcut to it using the technique used in Xcode duplicate line. I have not gone so far.

Multiple Assistant Editors

If you are using multiple assistant editors, you can use graphical navigation chooser to choose the destination of each action. You can start in any editor and you can even swap the content of two assistant editors this way.

, - Open in... and choose the second editor
J - Move Focus to Editor... and choose the second editor (or use ^` multiple times)
^ - Go Back in... and choose the first editor

Marián Černý
  • 15,096
  • 4
  • 70
  • 83
  • To clarify, the 'current file' is defined by where your cursor is. – Robert Sep 03 '15 at 14:23
  • If you also add `Shift` to this shortcut, you will be able to choose any editor as a destination (not just Primary editor). – DanSkeel Jan 20 '16 at 16:41
  • Second half of swap can be made by pressing `^`+`⌥`+`⌘`+`←`. (go back and open result in assistant editor) – DanSkeel Jan 20 '16 at 17:21
  • @Marian. this works great. are you up for trying to get this working as a custom shortcut like duplicate line. I've been using duplicate line shortcut for years and its great so similar shortcut to swap editors would be useful. I'll give it a go myself but the not sure how to do the last bit where it brings up the window where you choose the final editor. – lozflan Aug 29 '18 at 21:38
15

There is a very easy way to do this. In the assistant editor, there is a bar at the top that shows the path of the file in the editor. Drag that file's icon into the same bar in the main editor.

Boom! swapped.

Keep in mind, that you need to be set up this way to pull this off:

  • Have the "Assistant Editor" selected
  • The Assistant Editor needs to be set to Automatic or "Counterparts" for the swap to work.

Here are the keyboard shortcuts to do the swap:

ctrl + command + up

or

ctrl + command + down

Amir Memon
  • 416
  • 3
  • 10
  • 2
    Could you please upload a screen shot? I could not follow your instruction. – Philip007 Nov 03 '12 at 12:06
  • 4
    Dragging the path doesn't do anything: just acts as if you'd clicked it and opens the list. – Luke Nov 30 '12 at 10:58
  • 1
    it works if you drag the icon of the file, but in this way it will open the file in both editors, not swap the two.. – hariseldon78 Jul 01 '13 at 23:53
  • hariseldon78, if you have "assistant editor" selected AND set to automatic/counterparts, it will actually swap. If it's set to manual, it won't. – Amir Memon Aug 20 '13 at 20:29
  • 3
    Not quite the answer to the question in a general context – ATV May 06 '16 at 04:48
9

You can open active document in any other editor by pressing

,


I would use it like this:

Suppose we have two editors E1 and E2

  1. Choose E1
  2. Press ,
  3. In graphical navigation chooser choose E2

    Original content of E1 now opened both in E1 and E2

  4. click the back arrow of E2 (or just press )
  5. In graphical navigation chooser choose E1

Congratulations, you've swapped content of two editors

You could press just instead of last two steps, because opens file in assistant editor.


P.S. Meaning of :
is resposible for graphical navigation chooser
is responsible for Go back

DanSkeel
  • 3,853
  • 35
  • 54
2

ctr + cmd + up

or

ctr + cmd + down

If you have assistant view open it will automatically open the counterpart file. This way if you switch back and forth in your main window your counterpart window will update with the header/implementation file.

Freddy
  • 2,249
  • 1
  • 22
  • 31
  • 3
    This is good if you're using the Assistant with counterparts but doesn't work in the general case. Also your keyboard focus would have to already be on the Primary Editor. – funroll Jun 12 '13 at 02:15
1
  1. Position the cursor over the symbol you want to load (e.g. the method or class name)
  2. Command + Shift + O to load the quick open window (it will prepopulate with the item underneath the cursor)
  3. Shift + Option + Enter loads a UI that lets you choose a tab or editor
  4. It should select the primary editor by default, so just press Enter!

You can also use Command + Shift + Option + Click.

funroll
  • 35,925
  • 7
  • 54
  • 59