XCode 7.3 beta - how to force strict search for code autocomplete for Objective-C? - xcode

I'm running into an issue where XCode 7.3 autocomplete searches all possible constants using some kind of weird pattern matching algorithm. The result is that I practically have to spell the entire constant name before autocomplete allows me to press "enter" to select the suggestion.
How can I force XCode to do old, strict "begins with" autocomplete search algorithm?
For example, attempting to search for constant kEditTag, I would expect it to show up once I type kEd..., while currently I have to type keditta, to have the suggestion even show up in the autocomplete list, making it rather useless:

Please go to XCode -> Preferences -> Text Editing and "Enable type-over completions" . This should do the trick

When start to type write 2 or 3 character so xcode can interprete what you want in completion. use ctrl + space

Related

How to disable generating special characters when pressing the `alt+a`/`option+a` keybinding in Mac OS (`⌥+a` )? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
There is a behavior in my mac that I'm trying to disable.
When I'm in any text editor and typing a key combination using the alt/option+any letter, the output will be special characters.
For example:
the combination alt+a will generate å.
the combination alt+x will generate ≈.
I want to cancel this behavior.
I'm a programmer and when I use my code editor I want to map some keybinding (keyboard shortcuts) to the alt key (⌥+a for example) but when I do that it doesn't execute because it generates the special characters.
I guess that the special character has a priority over my code editor shortcuts.
Do you know how can I disable this default behavior?
Thank you
You can create a custom keyboard mapping with option-letters all set to BLANK using online tool from this webpage. You can create a custom mapping in several clicks out of almost any keyboard layout. Proved to work on MacOSX 10.7+ with IntelliJ Idea, Php/WebStorm, NetBeans, Eclipse.
Select "Set blank for option key" radio in the form, submit the form, and download a patched keyboard layout with "option" key feature disabled. I'm sharing the working file for standard US English keyboard layout:
MacOS <= 10.10
MacOS >= 10.11
After enabling this custom mapping, if you type a letter with "option" key pressed, nothing is printed to text output. But, the "option key press" is triggered by OS, and detected by your IDE. So you get exactly the same behaviour as you have for other command keys!
Download the key mapping file My Layout.keylayout.
Move it to ~/Library/Keyboard\ Layouts/
Open System Preferences -> Language Input Methods (or Keyboard -> Input Sources)
Go to Input Sources -> (hit +) -> Select Others
You should find My Layout in the list and select it.
Step 4 can change slightly across MacOS versions. Please be patient to find keyboard layouts list in the settings.
Here are detailed steps to Sebastian Zaha's answer. (I ended up fumbling around a bit before I got this working).
(Alternatively here is a ready made file by me)
Download Ukelele
You can run it directly from the .dmg file
File -> New Based On Current Input Source (I had US selected)
Click Modifiers button
Select each modifier from list that have Left Down or Right Down in the Option column. (There could be some like Either Down OR Up too, but AFAIK you can leave those.)
Press the minus button for each like this
Go to Keyboard menu -> Set Keyboard Name
Change the name somehow to make it easier to identify
Go to File -> Save as
Save to ~/Library/Keyboard\ Layouts/ with suffix .keylayout
Log out from your Mac OS account
Log back in
Go to System Preferences -> Keyboard -> Input Sources
Hit the + button -> Others -> Your new layout should be available
Add the new layout
Possibly leave original keyboard layout too and configure some nice way to switch
I was having the exact same problem, in the exact same IDE.
The solution to this is to download Ukulele from here:
http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=ukelele
In the application you can create a new keylayout using File -> New from current source. Pressing Option will show you in the place for Option-b a red colored key - meaning it's a dead key. Double clicking it will allow you to change it from a dead key to an output key. When prompted for the output you can put in the same thing (by pressing Option-b).
Thus it will output the same character but will not be considered a dead key, so Intellij can bind it as a shortcut.
To enable your new layout you must save it into your ~/Library/Keyboard Layouts (it helps if you give it a new name with Keyboard -> Set Keyboard Name), and then enable it from System Preferences -> Language & Text.
Use Ctrl-Alt-<MNEMONIC>. IMHO much easier than having to install and configure a separate app.
I had the same issue on a new Macbook with VSCode which had worked fine on my old Macbook. When I typed alt-shift-f for format I got unicode instead. I realised the difference was my old Macbook had a British keyboard setup instead of the default "ABC - Extended". Adding the British keyboard fixed the issue for me.
I have a solution!
Place a file at: ~/Library/KeyBindings/DefaultKeyBinding.dict as:
/* ~/Library/KeyBindings/DefaultKeyBinding.dict */
{
/* Additional Emacs bindings */
"~f" = "moveWordForward:";
"~b" = "moveWordBackward:";
"~<" = "moveToBeginningOfDocument:";
"~>" = "moveToEndOfDocument:";
"~v" = "pageUp:";
"~d" = "deleteWordForward:";
"~^h" = "deleteWordBackward:";
"~\010" = "deleteWordBackward:"; /* Option-backspace */
"~\177" = "deleteWordBackward:"; /* Option-delete */
/* Escape should really be complete: */
"\033" = "complete:"; /* Escape */
}
It will hide the original textual input. But you can still get that by using Ctrl-Q before the combination.
So Ctrl-Q Alt-f gives me ƒ for example.
In fact, I'm writing this answer with the option keybindings enabled.
You can also add other keys you like! Official reference:
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html
Here is a good list of things you can bind to:
https://www.hcs.harvard.edu/~jrus/site/selectors.html
Oh, by the way, if you bind a key to an undefined action, your application will have a memory leak and your system will run out of memory in a few seconds. Tested on el capitan, in the hard way.
Using the Apple JRE, the Option key combinations will work as shortcuts instead of inserting special characters.
Download link:
https://support.apple.com/kb/DL1572?locale=en_US
It's an old outdated JRE (based on Java 6) but as of October 2015 it's still what seems to work best w/ my JetBrains RubyMine installation. (Anything else, the keys go back to inserting special characters.)
Use ABC as input method instead of ABC-Extended, then option + [char] would be able to use the application shortcut instead of showing special character.
I have found a decent workaround.
I use the software Karabiner to change my right enter key to control when held down.
So what iv done is remapped the option key to option+cmd+control, as I'm not aware of any commands that use all three modifiers. Now I can map the right shortcuts without any characters. But you could also map to additional keys if required
Add this to your private.xml: (in between root)
<item>
<name>Change option Key to cmd + control + option</name>
<identifier>private.optiontoelse</identifier>
<autogen>__KeyToKey__
KeyCode::OPTION_L,
KeyCode::OPTION_L, ModifierFlag::CONTROL_L | ModifierFlag::COMMAND_L</autogen>
<autogen>__KeyToKey__
KeyCode::OPTION_R,
KeyCode::OPTION_R, ModifierFlag::CONTROL_R | ModifierFlag::COMMAND_R</autogen>
</item>
Then reload the xml and enable the option at the top of the 'Change Key' tab
https://pqrs.org/osx/karabiner/

How can I find and replace inside a selection in Xcode?

In Xcode < 4, you could hold the "option" key, and the "Replace All" button would change to "Replace in Selection". As of Xcode 4, this does nothing. Anyone know if there's a new way to do it, or is it bug filing time?
This appears to be working again now, at least in Xcode 4.4.1.
When the find/replace bar appears at the top of the editor, holding down the option key on the keyboard causes "Replace in Selection" to appear in lieu of "Replace All."
I'm glad, because this was an ANNOYING omission.
Another workaround:
In Xcode, select the text, press copy
In a terminal session:
pbpaste|sed 's/SOURCETEXT/NEWTEXT/g'|pbcopy
Return to Xcode window, press paste
Since the original should still be selected, it will just be replaced. You could probably build a simple shell script to do this.
Doug
An few images to supplement the chosen answer:
And holding down Option:
See also
Find/Replace in Xcode using Regular Expressions
Seems like missing functionality. You should file a bug report.
I'm upset that they took out this functionality, as I used it constantly, but here's my workaround. Copy your selected text from Xcode4 to TextEdit or some other word processor, do the find and replace there, and then copy the results back into Xcode.
It's not sexy but it's worth it if you do a lot of these "find and replace on my selection", and you leave the word processor open in Spaces as you work.
They should add "my selection" as an alternative to "workspace" and "my scope".
There is another way only replace the matches you find, rather than just this one or all of them.
I suggest you save a copy first, just in case....
In Find and Replace, Show Find Options (you can do this by pressing the magnifying glass).
Press Preview.
Uncheck all the ones you don't want replacing.
Press Replace
Hope that helps, it did me.
Not ideal, but not too bad:
Do a find and replace in workspace (cmd-opt-shift-f) enter your desired find/replace
Enter your desired search term and hit return
Select the range of replacements from the list of matches on the left
Hit replace (not replace all)
To replace text in a selection using Xcode 9
Press Option-Command-F to bring up the find/replace box.
Enter the search and replace string. Changing the search string will lose any existing selection, so..
Make your selection (again). (If you don't do this, the selection will be the first search string found only)
Hold down the key and "Replace All" will change to "Replace Selection", then click it.
Once you understand that you make your selection AFTER you have entered the search string, then this is not that clumbersome and works fine.
I find alt-command-f easier for local find and replace (4.3) and then working around your selection.
EthenA.Wilson asked in a comment to the OP a couple of days ago:
"Is there a way to do this in Xcode 5?"
For the benefit of those who, like me, had been searching for it, here's how:
After you put your Find and Replace terms in the bars at the top left-hand side of the editor page, select the text you want to search in, then look at the top right-hand side (same bar). You'll see where it says "All", right next to "Replace." Now press the Option key. "All" will change to "All in Selection." Click it, and you're done. Could be a bit more intuitive, but the functionality is there in Xcode 5.
Naturally, good idea to take a snapshot before you click!
HTH!
Not sure which feature prior to Xcode 4 you're referring to, but the shortcut Command+Shift+E gives you "Use Selection for Replace". If you're talking about "Find and Replace in Workspace" (Command+Option+Shift+F), then what you need to do is run your find and then hold down "Shift" or "Command" on the selections shown and then hit "Replace".

Where is the basic Control-TAB (MRU) behavior in Xcode?

In most multi-document editors for windowing environments, Control-TAB will utilize an MRU list to bring the user back to the last visible file. What is the appropriate command to accomplish this in Xcode 3.x?
I currently have Ctrl-TAB mapped to "View|Previous File", however this does not appear to be an MRU. Worse yet, if it hits the "beginning" of the list (should be a circular buffer), it falls back on inserting an actual TAB character into the text editor.
As of Xcode Version 3, there isn't anything that's exactly like the MRU you describe - however, check out the discussion on this page for some options that will get you closer to the behavior you want.
In recent XCode (10.3), when in a code editor press:
ctrl+1, right, right
Then use up and down keys and enter
to select from the MRU sorted list of recent files.
There is even an option to increase the size of the history.
In Xcode 3 (or any Mac application) you can use Command-Tilde (⌘~) to switch between open windows.
In Xcode 4 you use ⌘} for next tab and ⌘{ for previous tab - command shift bracket.
As a side note, for some reason Xcode 4 won't let me set the key binding for previous/next tab to the standard Control-Tab. When I try it puts in Command-Control-Tab.

Generic Xcode usage questions

I have 3 general questions related to the usage of xCode. Any help would be greatly appreciated please:
Whenever I open documentation, the left content/index column is always small and I have to drag it wider. Is there a way to permanently set its size?
Is there a way to perform a wildcard search and replace e.g. I have 3 lines:
var1Letter = #"A";
var2Letter = #"A";
var3Letter = #"A";
In the above I would like to replace var?letter in 1 go.
How do I set the default SDK?
Thanks.
re #2: Xcode can use regular expressions. You need to select the regular expression type though (it usually says textual) and that will let you do a search and replace. Xcode uses the ICU regex syntax.
To do the wildcard search, use regular expressions and use \n in the replacement text.
I'm using Xcode 3.2, but I think that older versions use the same regular expression syntax. Use the Find… (cmd-F) command. Choose "Find & Replace" from the pop-up menu. Choose "Regular Expression" mode from the pop-up menu in the search text field. Enter "var(\d+)Letter" for the search text, and "var\1letter" for the replacement text.
The "\d+" syntax matches any sequence of one or more digits. The "\1" is replaced by the text matched by the first set of parentheses in the search text.
Here's all I know:
Not sure; I have seen this problem, too, and don't know of a workaround.
As far as I know XCode doesn't handle regular-expression-based search/replace, which is what you'd need for this situation.
The setting you're looking for is "Base SDK", which can be configured both per-project and per-target (which overrides the project setting) by right-clicking on the project icon or the target icon, respectively, and choosing "Get Info" from the context menu. The Base SDK setting is one of the first under the Build tab.
For #3, There's no way to set new default SDK for all new projects that you create. The easiest way that I've found is to create an .xcconfig file that gets imported to every new project that I make.
An alternative to this would be to edit the default Xcode project (The base template for a base application is found at Developer/Library/Xcode/Project Templates/Application/Cocoa Application/Cocoa Application/__PROJECTNAME__.xcodeprjo/project.pbxproj) and change the SDKROOT value.

How can I turn on parenthesis matching in Xcode?

Curly brace matching was pretty easy to turn on. How can I turn on parenthesis matching in Xcode?
on Xcode Version 6.1 (6A1052d), you just need to double click on one of the parenthesis and the entire code that the parenthesis is scoping out is highlighted.
for example, if you have a code like the one below and you double click '{' or '}' bracket the entire code in their scope is highlighted :
if(condition == true)
{
//do something
}
Choose editor -> code folding -> focus
Edit
In XCode 9 the only solution is to put mouse over parentheses while pressing command button. Only this works.
Previous
To extend the other answers
it is possible to roll in/out code inside brackets.
Choose Editor > Structure > Balance Delimiter
url
Nevertheless, as already written earlier, the major feature is
Editor > Code Folding > Focus Follows Selection
press command key and its hover the brace and parenthesis ...
You must be running Xcode in Snow Leopard and install Xcode from the Snow Leopard disc that you got at WWDC. If you did not get a Snow Leopard disk, then you are out of luck unless you find one elsewhere.
The version of Xcode needed is 3.2 and the other components in the about page are:
Component versions
Xcode IDE: 1600.0
Xcode Core: 1599.0
ToolSupport: 1591.0
Please have a look at below answer for Xcode 9.0 and above:
Xcode highlights an opening delimiter (brace, bracket, parenthesis) when you move the cursor left-to-right over the matching closing delimiter. The highlight animation lasts about 1 second total, which is plenty in the case where you need a hint (and as you say the other delimiter is nearby).
If you need a more persistent indication, you can double-click either the opening or the closing delimiter, and Xcode will select both delimiters and their contents. (You can also use this, for example, to get quickly to one delimiter from another, even if they're far apart — double-click the delimiter you can see, use the left or right arrow to get the other end of the selection.)
With latest xcode13 we can permanent active this option with
"Xcode" --> "Preference" ---> "Text Editing" and by enabling "Code folding ribbon"
Thanks

Resources