Is there a shortcut to search the word under cursor in Xcode? - xcode

The functionality I'm talking about is in VI/VIM. ie. When the cursor is over the text of a word like say jiggle in command mode, press * to search for the next instance of jiggle. I use this all the time in VIM. Does such a shortcut exist for Xcode? or can we only double-click to highlight, CMD + C, CMD + F, CMD + V, and hit Enter?

Ok, Phrogz has a good solution, but I found a simpler way to do this...
To search consecutive instances of a word in Xcode:
Double-click the word you would like to find the next instance(s) of, then as Phrogz mentioned press ⌘ + E (Use Selection for Find) and then ⌘ + G (Find Next) to search for the next occurrence(s)

Cmd + Ctrl + T will invoke the menu item "Edit All in Scope". That will highlight all uses of the current identifier and allow you to edit all simultaneously.
Not exactly the same thing, but I find it very useful for the sort of case you're talking about. Even if I don't need to edit an identifier, it's a nice way to quickly see all the places its used.

If you select the word (⌥←,⌥⇧→) you can press ⌘ + E (Use Selection for Find) and then ⌘ + G (Find Next) to search for the next occurrence.

You can combine the command+e, command+g to a shortcut
Find a file IDETextKeyBindingSet.plist in directory "/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/"
Open this file by Xcode
Add a Dictionary named Customized under the Root
Add a String named Move to Next Instance under the Customized
and set the value to selectWord:, useSelectionForFind:, findNext:
IDETextKeyBindingSet.plist
Restart Xcode and set the Key Bindings
Find Move to Next Instance and set the key to option+↓ (or other key you prefered)
Key Bindings

To search a word in the currently opened file using Xcode 5 and above:
Double click the word and then
shift optioncommand E
Now you can move to the next/previous instance using:
command G
or
shiftcommandG

Related

Visual Studio CTRL + F but how to work it?

I know I can use CTRL + F to search selection, current documet, all open documents etc. But is there a way to work witch search bar only with keyboard? For example to switch between searching option, expand the search bar etc.?
not sure if you want to have a single KB shortcut for every type of search (current document, all open docs, etc). But after pressing Ctrl+F you can press Tab a few times until you navigate to the search scope DDL and then press ↓ or ↑ to select the needed option.
Will it be easier for you than using the mouse? :)

Xcode - search text in all files

Is there a way to search through all Xcode project files? I know that I can find some text inside file with finder, but finding something with Xcode will be very helpful. When I press cmd+f I can only find or find and replace in current display file.
Use cmd + shift + f for complete Xcode search.
To do it simply from the UI, with a click
By default, this will be searching through the entire project searching for any files containing the specific string you entered.
From this point, you can start doing more stuffs like replace all, etc, like this
On the left hand side of the editor you have a magnifying glass. There's a search box there. That should do the trick. (it's called the search navigator)
cmd + shift + f opens it too.
cmd + shift + f
then press return key of you keyboard.
Use Command + 3 a minimum keyboard shortcut
or Command + Shift + f
In find use: Find > Text > Containing
Right Click on any text and select 'Find Selected Text in Workspace'
In my experience, cmd + shift + f requires cmd + c before hand to populate the search term. So, my go to search for text in all files is to do the above.

VS2010 formatting hotkey?

Is there a hot key to force VS to format the current line/block in C#? (Similar to what happens when you add a semicolon to the end of a line or add a closing brace)
You can see the shortcuts (they are dependent on your settings) in the Edit/Advanced menu, where you have Format Document and Format Selection.
Place the cursor on one brace, then press Ctrl+Shift+{, then Ctrl+E, F.
You can also format the entire document by pressing Ctrl+E, D.
There are:
Ctrl + K + D - it formats the whole document.
Ctrl + K + f - it formats the current selection.
These also appear under the Edit -> Advanced menu.
See this document on MSDN, these appear under Edit.FormatDocument and Edit.FormatSelection.

Move to beginning of text in Xcode

I know I can bind keys to "Move to beginning of line", but this ignores the indentation.
What I'm looking for is to move to the beginning of text on a line, so that:
CGRect example = CGRectMake(view.frame.origin.x,
view.frame.origin.y,|
pressing a key will move the cursor to the beginning of the "view" word in this example (char | is cursor).
It is extremely annoying that currently I have to press 3 commands to get to the beginning of the text when inside a code block (cmd <-, opt ->, opt <-).
There's no standard way to accomplish it in XCode, so I've written an XCode plugin implementing this feature:
https://github.com/insanehunter/XCode4_beginning_of_line
Under the hood it overrides XCode's source editor keyboard action dispatch method and implements beginning/ending of line jumps in enhanced way.
Hope it helped.
As of 7.3 (not sure when it was added), Xcode seems to have turned this on by default. Cmd-left in the Key Bindings preference pane is now bound to "Move to Beginning of Text."
Personally, this drives me bonkers, so I've changed it back to "Move to Beginning of Line." But for people who want this behavior, it's good to know that there's now a built-in way to get it.
If you've copied your Key Bindings Set, you may not be seeing the new behavior yet. If not, just search for "beginning" in the Key Bindings preferences and adjust them to your liking.
Use option + ← to jump across entire words.
(That means, hold the option while pressing the left arrow key)
Actually, there is a faster and simpler way to achieve this as Mac OS supports some Emacs (or Unix) keybindings quite well.
You can use Ctrl-a to jump to the beginning of a line. Which means, hold 'Ctrl' key and press 'a' on keyboard.
For your more information, it is also handy to use
Ctrl-e: jump to the end of a line
Ctrl-n: move to next line
Ctrl-p: move to previous line
What's more, these fast keys can be used in terminal and text fields such as this StackOverflow answer editor on Mac OS, too.
Hope that helps.
I'm using Xcode 7.2 and was able to make my own macro to automate those 3 commands you mentioned above (cmd <-, opt ->, opt <-). You can edit the IDETextKeyBindingSet.plist file which defines all the key-bindings to add your own.
Mine was located at /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist
Add the following to create your own macro
<key>Custom Keys</key>
<dict>
<key>Move to non-whitespace beginning of line</key>
<string>moveToBeginningOfLine:, moveSubWordForward:, moveSubWordBackward:</string>
</dict>
Relaunch xcode and in your Preferences > Key Bindings tab, search for your custom macro and set it to cmd <-. Now it will run those 3 commands and effectively moves your cursor to the beginning of the text in the line.
I don't have an exact solution, just one slight improvement for Xcode 4. You could set up a keyboard mapping for "Move Expression Left" (Xcode prefs > Key Bindings), which is a little more than Opt ←:
s = [NSString string] |
if | is the cursor position, pressing a "Move Expression Left" keystroke will bring it to the beginning of the expression on the left of it, so in that case before "[NSString". Opt ← will only move before "string".
(Side note: I do see an action command called "Move to Left end of line" and another one called "Move to beginning of line." To my experience, these do exactly the same behavior in Xcode 4.0.2: this looks to me like a bug, unless I'm missing something.)
It seems that the simplest way, as already mentioned is
1) Go to the beginning of the line (Cmd + left arrow key)
2) Jump to right word (Alt + right arrow key)
3) Jump to left word (Alt + left arrow key)
Unfortunately (Alt + left arrow key) and (Alt + right arrow key) ignores comments, brackets, etc and therefore the method above will not always work. If this is not a problem, then there is also one solution for the BetterTouchTool users. One can create a sequence of actions (commands) that will be called one after another and assign it to Home button. To do so, open the preferences, go to Keyboard tab, Add new shortcut and assign Home button to the (Cmd + left arrow key). Then click Assign additional actions twice, first one for the (Alt + right arrow key) and the second one for the (Alt + left arrow) key commands.
Hopefully this helps.
Tested on XCode 10:
Step1: Open the file located in the next path by a text editor
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist
Add the next elements to the end of the file:
<key>Sublime Commands</key>
<dict>
<key>Cut Current Line</key>
<string>selectLine:, cut:</string>
<key>Copy Current Line</key>
<string>selectLine:, copy:</string>
<key>Duplicate Current Line</key>
<string>selectLine:, copy:, moveToBeginningOfLine:, paste:, moveToEndOfLine:</string>
<key>Delete Current Line</key>
<string>selectLine:, deleteToEndOfLine:, moveToEndOfLine:</string>
<key>Move To First Char In Line</key>
<string>moveToBeginningOfLine:, moveSubWordForward:, moveSubWordBackward:</string>
</dict>
The previous last key 'Move To First Char In Line' will do your request, but I mentioned also other keys.
Now save the file.
Step2: Close XCode and reopen it.
Step3: Navigate to keybinding in xcode preferences then assign your shortcut.
XCode -> Preferences -> Key Bindings
Then search for 'Move To First Char In Line' and assign your shortcut.
In this Xcode extension, Linex, the feature Line Beginning can move to the first non-whitespace character in a line, and also toggle between that and the real beginning.
Works for Xcode 9, perhaps Xcode 8.

How can I set up Cocoa style keyboard shortcuts in Mac Terminal.app?

I love cocoa style keyboard shortcuts and am constantly frustrated that Terminal doesn't behave in the same way. Does anyone know how to set common cocoa-style keyboard shortcuts in Terminal.app?
I found a blog post that describes how to do this in iTerm: http://blog.jcoffin.com/2008/12/06/mac-keyboard-shortcuts-iterm/. However, I like Terminal.app better for a number of reasons.
Terminal.app allows you to define custom keyboard shortcuts, but it doesn't let you use the command key. It also doesn't let you define a key for "delete", but for some reason allows "forward delete" (?).
The main ones I want are:
Option + ←/→ for moving the cursor a full word
Command + ←/→ for moving to the start/end of a line
Option + Del for deleting a full word
Command + Del for deleting a line
If I could just have these I would be happy :-)
I followed the instructions in this blog post from Allan Odgaard (of TextMate fame) to set up:
opt-arrow for word-movement
ctrl-arrow for moving to start/end of the line (though, to be honest, I end up using ctrl-a and ctrl-e much more often)
forward-delete (based on this comment which says to map it to ctrl-opt-d)
You can also check the "Use option as meta key" item to get opt-delete to perform word-deletion.
Unfortunately, as Allan says, you cannot bind to the normal delete key, nor can you use the Command key as a modifier.
You could use the ones from Unix terminal (shell), I think they work the same in Terminal app:
full word forward: Esc + F
full word backward: Esc + B
end of the line: Ctrl + E
beginning of the line: Ctrl + A
delete full word (cursor at the end of the word): Esc + Backspace (Mac Del?)
delete the whole command line: Ctrl + C

Resources