|
| 1 | +[Return to root](README.md) |
| 2 | + |
| 3 | +# Keyboard Shortcuts |
| 4 | + |
| 5 | +### Cheatsheet |
| 6 | + |
| 7 | +A handy list of Xcode keyboard shortcuts. |
| 8 | + |
| 9 | +Source: [Keith Harrison](https://useyourloaf.com/blog/xcode-keyboard-shortcuts/) |
| 10 | + |
| 11 | +### Jump to a specific line |
| 12 | + |
| 13 | +Open the file you want. Press **⌘L**, type a line number and Xcode will jump directly to that line. |
| 14 | + |
| 15 | +### Re-indenting/Formatting code |
| 16 | + |
| 17 | +Press **⌃I** to apply Xcode's indentation and formatting. |
| 18 | + |
| 19 | +### Adding comments quickly |
| 20 | + |
| 21 | +Use **⌘/** to toggle comments for the current line or selection. Use **⌥⌘/**, pressed directly before a method to have Xcode generate a documentation comment. |
| 22 | + |
| 23 | +Source: [Paul Hudson](https://www.hackingwithswift.com/articles/229/24-quick-xcode-tips) |
| 24 | + |
| 25 | +### Jump to file in source navigator |
| 26 | + |
| 27 | +Press **⌘⇧J** to quickly jump to the current open file in the navigator to easily see and select related files. |
| 28 | + |
| 29 | +Source: [Jeroen Leenarts](https://leenarts.net/2020/02/18/frequently-used-keyboard-shortcuts-i-use-inwith-xcode/) |
| 30 | + |
| 31 | +### Open the jump bar |
| 32 | + |
| 33 | +Press **⌃6** to open the symbol jump bar in Xcode. Now start typing. Try it, jumping to a function in the current file, never has been so easy. |
| 34 | + |
| 35 | +Source: [Jeroen Leenarts](https://leenarts.net/2020/02/18/frequently-used-keyboard-shortcuts-i-use-inwith-xcode/) |
| 36 | + |
| 37 | +### Remapping unhelpful keys |
| 38 | + |
| 39 | +Some great shortcuts (e.g. **⇧⌘O** for Open Quickly) are next to useless shortcuts (**⇧⌘P**, for the never times you want to print code.) It takes only seconds to remove unhelpful keys, and you can even remap things like **⌘P** to resuming SwiftUI's preview. |
| 40 | + |
| 41 | +Source: [Paul Hudson](https://www.hackingwithswift.com/articles/229/24-quick-xcode-tips) |
| 42 | + |
| 43 | +### Increase or decrease editor font size |
| 44 | + |
| 45 | +Press **⌘+** to increase and **⌘-** to decrease. |
| 46 | + |
| 47 | +### Move cursor to the top or bottom of the file |
| 48 | + |
| 49 | +Press **⌘↑** to move to the top of the file. Press **⌘↓** to move to the bottom of the file. |
| 50 | + |
| 51 | +### Show and hide debug area |
| 52 | + |
| 53 | +Press **⌘⇧Y** to open and close the debug area. |
| 54 | + |
| 55 | +### Generating an interface file |
| 56 | + |
| 57 | +Press **⌃⌘⇧** to display a generated interface, showing properties, function signatures, and comments for a type. Press it again, to jump to tests for that file if they exist. |
| 58 | + |
| 59 | +Source: [Paul Hudson](https://www.hackingwithswift.com/articles/229/24-quick-xcode-tips) |
| 60 | + |
| 61 | +### Trigger Custom Behaviors |
| 62 | + |
| 63 | +If you find yourself wasting time continually opening and closing the `Navigator`, `Inspectors`, or the `Preview` when you switch the type of file you're working on, you can define custom `Behaviors` and assign keyboard shortcuts to them. |
| 64 | + |
| 65 | +Xcode Behaviors set the state of the Xcode interface when events occur such as a build starting. Custom Behaviors allow you to define your own triggers. |
| 66 | + |
| 67 | +* Go to `Xcode -> Preferences` |
| 68 | +* Open the `Behaviors` tab |
| 69 | +* Click `+` at the bottom of the list and name the new Behavior (E.g. `IB File`, `Code File`, `SwiftUI File`) |
| 70 | +* On the right side, set the state of the `Navigator`, `Inspectors`, `Preview` or other elements |
| 71 | +* Assign a keyboard shortcut next to each name |
| 72 | + |
| 73 | +Now you can quickly set the state of your panels to focus on the type of work you're doing. |
| 74 | + |
| 75 | +Source: [Erwin Mazariegos](https://github.com/erwinmaza) |
| 76 | + |
| 77 | +### Open Human Interface Guidelines |
| 78 | + |
| 79 | +Press **⌘⇧H** to open the Human Interface Guidelines in your web browser. |
| 80 | + |
| 81 | +### Show/hide the preview canvas |
| 82 | + |
| 83 | +It takes up a lot of space, you can quickly toggle it. |
| 84 | + |
| 85 | +> **⌘ ⌃ ↵** |
| 86 | +> `Editor menu > Canvas` |
| 87 | +
|
| 88 | +Source: [Sarun Wongpatcharapakorn](https://sarunw.com/posts/xcode-shortcuts-for-swiftui/) |
| 89 | + |
| 90 | +### Refresh Preview Canvas |
| 91 | + |
| 92 | +If you type too fast Xcode can stop updating the preview, so you may have to trigger a refresh. |
| 93 | + |
| 94 | +> **⌘ ⌥ P** |
| 95 | +> `Editor menu > Canvas > Refresh Canvas` |
| 96 | +
|
| 97 | +This will refresh your preview and start automatically updating again. |
| 98 | + |
| 99 | +Source: [Sarun Wongpatcharapakorn](https://sarunw.com/posts/xcode-shortcuts-for-swiftui/) |
| 100 | + |
| 101 | +### Move line of code up or down |
| 102 | + |
| 103 | +You can use a keyboard shortcut to move a line of code up or down, which can be useful for re-ordering things. This can be the current line or you can select multiple lines to move together. |
| 104 | + |
| 105 | +To move line of code up: |
| 106 | + |
| 107 | +> **⌘ ⌥ \[** |
| 108 | +> `Editor menu > Structure > Move Line Up` |
| 109 | +
|
| 110 | +To move line of code down: |
| 111 | + |
| 112 | +> **⌘ ⌥ \]** |
| 113 | +> `Editor menu > Structure > Move Line Down` |
| 114 | +
|
| 115 | +Source: [Sarun Wongpatcharapakorn](https://sarunw.com/posts/xcode-shortcuts-for-swiftui/) |
0 commit comments