Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a shortcut to search the word under cursor in 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?

like image 798
jcpennypincher Avatar asked Dec 07 '10 05:12

jcpennypincher


People also ask

How do I quick search in Xcode?

Find text or patterns in your source code To find text in a file, open the file in the Xcode source editor and choose Find > Find from the menu bar. Xcode displays the Find bar and its search controls at the top of the file. Enter a search term.

What is Command Shift G?

By hitting the keyboard shortcut Shift-Command-G on the desired clip, you can make personal notes about the footage. This organizational tool can be extremely effective when sharing your work with other editors and can be helpful if your work needs approval before being published online.

Which of the following shortcut key is used to find text?

Press Ctrl+F, and then type your search words.

How do I select a word in Xcode?

Hold down the Shift and Control keys, and press the Right-Arrow key.


4 Answers

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)

like image 189
jcpennypincher Avatar answered Oct 01 '22 21:10

jcpennypincher


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.

like image 29
Ken Avatar answered Oct 01 '22 20:10

Ken


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

like image 28
Phrogz Avatar answered Oct 01 '22 21:10

Phrogz


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

like image 34
Knuckles Huang Avatar answered Oct 01 '22 21:10

Knuckles Huang