Where can I edit multi-cursor of xcode? - xcode

I want to edit a multi-cursor (^ + shift + click) of Xcode but I don't find the option to edit it. Anybody know where is it?
Thanks

It appears that you want to replace control-shift-click with option-shift-click. I don't believe there is any way to do that.
(My original answer, outlining how multiple cursors work, is below.)
If you’re talking about multiple cursors, you do it with option-click and drag.
For example, I wanted to add some spacing in the definition of this array:
This is #32 in Hacking with Swift’s Xcode tips and tricks.
(That having been said, Hacking with Swift uses example of the writing of an memberwise init method. That is something probably more easily achieved with “Editor” » “Refactor” » “Generate Memberwise Initializer”.)
The control-shift-click is for adding a cursor. E.g., in this example, I “accidentally” missed a cursor on the first line, so I control-shift-clicked on first line to add the missing cursor:
And if you control-shift-click on an existing cursor, it will remove it, effectively toggling the various cursors.

Related

Is there a way to link specific lines (line numbers) of your code together in Xcode for easy reference?

I am fairly new to Xcode and I am wondering if there is a way to link two separate lines such as if I have a do while loop I can 1. see which line it is associated with 2. see which 'do' line number is associated with which 'while' line number. I know this is a subjective question and maybe not fitting for this kind of platform, however I'm unsure where to ask it. I'd appreciate the help though.
This is built into Xcode. In properties, turn on the "Code folding ribbon" in the "Text Editing" pane:
This lets you see immediately what lines of code are part of a block, or collapse sections so you can focus on the structure. Look at the Editor menu, under "Code Folding" for options and keystrokes.

Is there a quick way to fold and unfold comments in xcode 7?

Is there a quick way to fold and unfold a block of comments in xcode 7?
While I'm trying out new code I like to keep different versions of a "solution" until I decide which one is my favorite and delete the rejected material.
The ability to Fold & Unfold code blocks is set to OFF within Xcode 7.
Steps to change this:
Select Xcode (top left)
Choose Preferences
Navigate to Text Editing (center)
Tick the option Code folding ribbon
Once you've done this, you'll be able to collapse the comments, along with blocks of code.
I hope this helps!
.
Added Picture Reference
Code-folding block comments does not work in Xcode 7 - 7.2.1 in Swift files.
You can, however, hack it by using an empty closure to surround the comments. This will also work with multiple line comments too.
_ = { /* Comment
myCommented.code
*/ }
Definitely a hack, but could save you lots of scrolling around.

Improving development flow and editing with XCode.

XCode is a little weak in the way that it obliges you to format code, and the restrictions it places on you. I'm thinking of things such as select a block of code and use tab to reposition the whole block, which is very useful for cleaning up indenting, amongst other things.
I realise that I can use an external editor (such as Sublime Text 2, which is superb and my daily editor) to edit code, but I'm wondering if there are any plugins or tools which exist out there which integrate into xcode to improve this development experience.
What kind of extensions exist for xcode, or if there aren't any, are there any lesser-known features which assist in improving this?
It's hard to give you an answer, as we don't know what features you use elsewhere that you think are missing in Xcode. For example, you can move a block of code in or out by pressing Cmd-{ or Cmd-}. Or you can "fix" the indenting by using ctrl-i as jrturton pointed out above. All of the emacs keybindings work. In fact, you should look over the key bindings in the prefs to see what other things are possible. Some of my favorites are:
1) Select a word and hit Cmd-E to make it the search term. Then Cmd-G to find the next instance.
2) F6 to step over in the debugger, F7 to step in and F8 to step out
3) As much as I hate command lines, gdb has a number of useful commands for calling methods while stopped at a breakpoint. You can call any function or C++ or Objective-C method using the call command. (Type help call at the gdb prompt to learn more.)
4) If your index is up-to-date, you should be able to Cmd-click on a symbol to go to it's definition, or option-Click to see its documentation.
Are those the sorts of things you're looking for? If not, please give examples of what you want. As far as I know there is no plug-in mechanism in Xcode 4, so no extensions exist.
Though the first answer is a great one (learned a lot from it), I wanted to add a little hint that helps me a lot when pasting codesnippets. A lot of times xCode copies indentation in a way I don't like and then I have to reindent the whole snippet.
What I started to do is jump to the first char in line (ctrl + a | cmd + ArrowLeft) and either paste the code immediatly, or indent by one or two before pasting, dependend if I'm in a function, loop etc.

Is there a way to jump to a specific method in Xcode?

I'm using Xcode 4.3 for Objective-C development.
One feature that I like in other text editors (I know Xcode is an IDE), is jumping to a method definition within the same code file.
For example if I'm in #implementation of Calculator and calculator has 10 methods, I will like a way to jump between them.
If I press command+L I can jump to a specific line number, is there a way to jump in a similar way but to a method definition? e.g. instead of typing the line number to type only the beginning of the method name.
Can I open somehow a dialog box, type the beginning of a method signature and see instantly the search results and If I pick one method it will get me to it?
Is there a way to jump from a method to the next one?
I think this is what you're looking for:
Type ctrl-6 to activate the "Show Document Items" in the "Jump Bar". Then start typing part of the method you are looking for to narrow the results.
Example:
To jump straight to - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Type ctrl-6, type "cellFor", arrow down so the method is highlighted, and press Enter. The Editor will jump right to that method.
Incidentally, you can use ctrl-1, ctrl-2, ctrl-3, etc. to access the different sections of the "Jump Bar".
If I understand you correctly, try Command-Shift-O. It also doubles as a file finder.
Perhaps I'm not understanding what you need, but it seems like you have a couple of options.
Control+Command+J should take you to a definition.
Control+Command+Up/Control+Command+Down will toggle between .h/.m files.
While in the .m file, I use the dropdown for the methods often.
If you want to press a command key sequence like Command + Option + ↓ to jump to the next method, or Command + Option + ↑ to jump to the previous method, there is no such animal in Xcode. Prior macOS development tools had such a capability, but Xcode is seriously lacking in the basics...
The fastest jump back and forth in methods in a source file is to perform a Command + F (Find) on [\-\+][ \t]*\( as a regular expression. Then you can Command + G (Find Next) to go to the next method or Command + Shift + G (Find Previous) to go to the prior method.
If you are disciplined in your method definitions, you might be able to search for - ( or + ( as a normal text string instead... a tad faster.
If this is a serious itch to scratch, maybe it is worth creating an Xcode plugin (as silly as this sounds for such a basic feature)... and post a link here for the rest of us ;-)
Select a symbol (could be a method, but doesn't have to be) and right-click (or control-click). The contextual menu that pops up has a "Jump to definition" command. Control-command-J is a shortcut for that.
If the thing you're looking for isn't visible, you can use the Search Navigator (Command-3) to search through the code.
Depending on what you're looking for, you may also find the Quick Help feature in the Utilities panel helpful. If you select a symbol, Quick Help will give you at least some basic information about that symbol. For symbols in the iOS or MacOS X API's, you get quite a bit of help. If you've selected your own symbol, it'll tell you where that symbol is declared, and you can click on the file name to jump to the declaration.
I don't think there's a command to jump to the next method (where in the method would you want to jump to?). If you have a need for that sort of thing, you might find Xcode's code folding features useful. You can fold an entire method or just some of the blocks within the method. Very helpful for getting the lay of the land when you're looking at a large file for the first time.

vim trick to align blocks/end keywords in Ruby?

Is there a way to simply have my blocks and their closing end keyword align properly with vim? If I have a function which is nested with several conditions, things can start to get ugly fast. Can vim save the day?
Sure. Just select the relevant block of code and press =.
There's also a nice Vim plugin called endwise that automatically inserts the ends for you.
gg=G
(go to top, re-indent all the way down to the bottom)

Resources