tags:

views:

803

answers:

3
+3  Q: 

XCode Mark

Is it possible to bookmark a line in XCode similar to the "mark" functionality in emacs? Also is there a shortcut used I can use to jump to a line number? My source code is becoming long and hard to navigate.

+9  A: 

Yes; if you place the text caret on the line that you want to bookmark and select Edit > Add to Bookmarks (or ⌘D) you can add that line to the bookmarks in your project. You can then access these bookmarks from the Bookmarks item in the Groups & Files pane.

To go to a certain line, choose Edit > Go to Line... from the menu (or ⌘L), and type in the line number you want to navigate to.

I would also recommend that you use the #pragma mark directive to help you navigate around in source files. It takes the format:

#pragma mark <Label>

And will show up in the functions popup menu at the top of your source file; it makes it much easier to navigate around your code by grouping together common functions, improving the overall structure and readability of your code.

Perspx
Man, I learn something new about Xcode every day. I had no idea about the bookmarks feature. I love the #pragma mark and use it all the time. Note that #pragma mark - will cause Xcode to display a horizontal separator in the functions popup. It's nice to put between multiple @implementation sections in a single file, etc.
Quinn Taylor
A: 

You can bookmark an individual line in a file: in your .emacs file

(global-set-key "\C-cb" 'bookmark-map)

sets it up, so:

control-c b m sets a bookmark (you can name it whatever you want.)

control-c b j jumps to a bookmark (it asks which bookmark you want)

Also:

(global-set-key [f1]  'goto-line)

sets F1 to ask for a line number and jump to that file

Brian Postow
You answered another question but those are two useful tips! I must have not been very clear.
Your question was fine, most of us understood you were looking for an Xcode feature. Sometimes fans just can't resist advocating emacs. ;-)
Quinn Taylor
@Quinn, oops, yeah. Also, I'm dyslexic, and sometimes I get things like that backwards...I really did think OP was looking for emacs commands similar to things in XCode rather than the other way around... Reading Fail.
Brian Postow
Also, I was going to delete my non-answer but figured it might be helpful to someone else...
Brian Postow
+1  A: 

You can also use the "mark" key sequence, control-@ or control-space, then you can use Delete to Mark (control-W), Select to Mark (control-X control-M), and Swap With Mark (control-X control-X). These emacs-like key bindings are supported in all Cocoa text views in Mac OS X, and you can customize the keybindings for Xcode in Xcode > Preferences > Key Bindings > Text Key Bindings.

cdespinosa