Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode 5 -- Jump To Previous Cursor Location

I would like to jump to the previous cursor position within a file in XCode 5 (with either a keyboard hotkey or a drop-down menu path).

This SO post worked for XCode 3: Does XCode have a cursor navigation stack like Visual Studio?

But for XCode 5, I could not find this functionality here: http://cloud.github.com/downloads/Machx/Xcode-Keyboard-Shortcuts/Xcode_Shortcuts.pdf, nor in the Apple Documentation here: https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/xcode_help-command_shortcuts/Introduction/Introduction.html#//apple_ref/doc/uid/TP40010560-CH1-SW1

EDIT

Sorry I wasn't clear earlier. I do not want to switch between files. As the answers below state, that is what ctrl+cmd+left/right does. I want to switch between cursor positions within a file. For example:

I am working in MyViewController.m.

I write a function -(void)doStuff at line 178.

In -(void)doStuff, I realize that I need to update an @property to be readwrite.

I go to the top of MyViewController.m to line 10. I add the line @property (nonatomic, strong, readwrite) NSMutableArray *myArray;

Now I want to return to finish writing my -(void)doStuff method. What is the best way to get there? This is when I'd like to say "Go to the last text cursor position."

like image 661
rizzes Avatar asked May 07 '14 20:05

rizzes


4 Answers

As Owen commented on your post, I believe the behaviour you want is to Go Forward/Backward, which is a behaviour represented by those two arrows at the top left of the text entry field:

Location of Go Forward/Backward buttons

In the pdf you linked these actions actually have shortcuts to the keys cmd+control+arrow, where the arrow key you press represents forward/backward motion through your XCode behaviour (left being back, right being forward).

like image 79
niksawtschuk Avatar answered Dec 01 '22 00:12

niksawtschuk


A useful trick I found is to bind opening the Document Items menu (by default Ctrl + 6) to something easier to type for me. Then when I'm about to, say, jump to some method definition (that may or may not be in the same file I'm already in), I first open the Document Items menu then just hit Enter. That marks my current location in the navigation stack. It also marks the line the cursor is at in the current method, too.

enter image description here

It takes a little training to remember to mark your place, but being able to open that menu and hit Enter quickly from the keyboard makes it less painful to force Xcode to mark your navigation within a single file.

like image 21
CIFilter Avatar answered Dec 01 '22 01:12

CIFilter


cmd+ctrl+arrow can work in this situation. But, it depends on how you change cursor locations.

If you use a file navigation control to change cursor location, cmd+ctrl+arrow will work. ctrl+6 switches to a method within a given file. If you start on line 178 then ctrl+6 to switch to another method on line 10, cmd+ctrl+arrow will return your cursor to line 178.

If you manually change cursor location, cmd+ctrl+arrow will not work. If you start on line 178 then scroll to line 10, cmd+ctrl+arrow will not return your cursor to line 178.

like image 27
rizzes Avatar answered Dec 01 '22 00:12

rizzes


I was searching for this for so long time and what works for me is:

⌃ + 2 (Ctrl + 2 - Shows previous history) then click ↓ - this will jump back to previous definition

⌃ + 3 (Ctrl + 3 - Shows next history) then click ↓ - this will jump to next definition

This will only work if you navigate through your class using ⌃ + 6 to jump between definitions.

like image 30
DenninDalke Avatar answered Dec 01 '22 01:12

DenninDalke