Overview
Xcode Shortcuts allow you to execute custom commands directly from Xcode using the cmd extension. You can create shortcuts that open files in external editors, run scripts, or perform any command-line operation using context from your current Xcode session.Shortcuts are only available when a file is open in Xcode.
Prerequisites
Before configuring shortcuts, ensure you have granted the Xcode Extension permission:Grant Xcode Extension Permission
Follow the installation guide to enable the Xcode Source Editor extension
Creating a Shortcut
1
Open Shortcut Settings
Go to Settings > Xcode Shortcuts in cmd
2
Add New Shortcut
Click “Add Shortcut” to create a new shortcut
3
Configure the Command
Enter your command using any of the available variablesExample Commands:
This opens the current file in VS Code, jumping to the selected line if available.
Copies the current file path to your clipboard.
Executes a custom script with the selected text and file path.
Opens a new Terminal window at your project directory.
Open file in VS Code at line number
Open file in VS Code at line number
Copy file path to clipboard
Copy file path to clipboard
Run a script with context
Run a script with context
Open terminal at project location
Open terminal at project location
Lint current file
Lint current file
4
Name Your Shortcut
Give your shortcut a descriptive name that will appear in Xcode’s menu (e.g., “Open in VS Code”, “Copy File Path”)
5
Test the Shortcut
Click the button to test your shortcut and verify it works correctly
6
Save
Click “Save” to add the shortcut
7
Save
You should now find your shortcut in Xcode under
Editor > cmd > shortcut nameSetting Up Key Bindings in Xcode
For quick access, it is recommended to assign keyboard shortcuts to your commands:1
Open Xcode Settings
In Xcode, go to Xcode > Settings > Key Bindings
2
Find Your Shortcut
Search for your shortcut name in the key bindings list, or for
cmd3
Assign a Key Combination
Click on the shortcut and press your desired key combination.
4
(Optional) Resolve conflict
If your desired key binding conflicts with one already defined in Xcode (there’s a lot!), change or remove the conflicting one.
5
Verify
The key binding is now active. Test it in any open Xcode file.
Variable Reference
Use these variables in your shortcut commands to access Xcode context:| Variable | Description | Example Value |
|---|---|---|
$FILEPATH | Absolute path to the current file | /Users/name/project/ContentView.swift |
$FILEPATH_FROM_GIT_ROOT | Relative path to the current file from the git root | ./project/ContentView.swift |
$SELECTED_LINE_NUMBER_START | First line of selection | 42 |
$SELECTED_LINE_NUMBER_END | Last line of selection | 58 |
$XCODE_PROJECT_PATH | The path to the project active in Xcode | /Users/name/swift-package /Users/name/app.xcodeproj |

