Add shortcuts to search any url with selected text. This is like custom search engines for Google Chrome, for Xcode. We use it to quickly search Sourcegraph directly to link code to documentation and share with co-workers.
- Download DMG from Releases.
- Open DMG.
- Drag the app into the Applications directory.
- Launch the app.
- (optional) Add/remove search urls as desired, you can always do this later.
- Open System Preferences > Extensions > Xcode Source Editor, make sure that UniversalSearch is enabled.
- If open, quit Xcode.
- Launch Xcode.
- Select some text in the editor (this must be on a single line right now).
- Go to Menu bar > Editor > XcodeUniversalSearch (at the bottom) and select an option to open your defined URL with the selection.
- Open XcodeUniversalSearch application.
- Add/delete/update your search commands as necessary.
- The Command name is what shows up in the Editor menu.
- When the command is selected, the selected text is filled into the URL template replacing any
%s
tokens, the resulting URL is launched. - In Options, you can configure additional logic for constructing the URL, see Options for more details.
For each URL, there are some additional options to configure how to construct the URL to open.
Default enabled
This configures if the full URL should be percent encoded before opening the URL. In order to be make it easier to copy and paste URLs, before percent encoding, this option will decode any existing percent encoded characters in the URL template. This should work most of the time, but there may be cases where this could cause some issues. If disabled, you will need to make sure that the URL template is appropriately percent encoded as a URL.
Note, the selected text will always be percent encoded regardless of this option - this option only affects the URL template.
Default disabled
Enables escaping characters in the selection text that might match regex metacharacters. This is done using NSRegularExpression.escapedPattern(for:), checkout those docs for an example of what this does.
This is useful if searching in a Sourcegraph regex pattern, typically your search from the selected text should be literal see the "Sourcegraph type" url template in the screenshot.
Default disabled
Enables escaping double quotes in the selection text.
This is useful if searching with a query which requires wrapping in double qoutes. For example, see "Sourcegraph literal" url template in the screenshot.
You can export and import your configuration as a JSON file. This allows you to backup or share your configurations. For example, the configuration used in the screenshot is this example_config.json.
- Launch Xcode.
- Open Xcode > Preferences > Key Bindings.
- Search for "XcodeUniversalSearch".
- Double click on the "Key" column next to the command for which to add a shortcut.
- Press your chosen shortcut keys.
- Click somewhere in the preferences pane, other than the "Key" column to save your key binding.
- Make sure to check for conflicts with your shortcut (shown on the footer of the preference panel while setting shortcuts and also in the Conflicts tab).
- Use your shortcut while editing.
Command | Shortcut |
---|---|
Literal search for seletion | ⌥s (Option-s) |
Search for Swift type with selected name | ⌥⇧S (Option-Shift-S) |
Search for file with selected text | ⌥f (Option-f) |
See Issues for TODOs and bugs.
All assets can be found in this XcodeUniversalSearch Figma (only the app icon right now).
- We use a replication of krzysztofzablocki/Versionable to make our models versionable.
- The magnifying glass asset used in the app icon is sourced from pngwing (non-commercial use license).