CamelCase cursor movement in Xcode
I mostly write Swift in Xcode these days. I can’t say I miss Java. I do, however, miss IntelliJ IDEA, and specifically, the little CamelHumps option:
This changes the behaviour when using the arrow keys to navigate between words (⌥+→, ⌥+← on MacOS) so that it respects CamelCase—i.e. it treats the word CamelCase
as two words, rather than one. This certainly made it easier for me when it came to renaming variables with long names:
I was always annoyed that Xcode didn’t seem to support this behaviour. It turns out it does! Xcode calls this ‘Move Subword,’ and by default maps it to the Control (^) key:
The immediate problem is that in all recent MacOS releases, ^+→, ^+← are mapped to workspace switching. Indeed, the default configuration warns it might be overridden by System Preferences!
You can, of course, just re-map it to the ⌥ key and override the default behaviour. Once you’ve cleared the conflicts, it works quite well…
The one caveat
The trade-off, at least as of Xcode 10.2.1, is that subword movement doesn’t seem to work in all of Xcode. And since the keymap applies for all of Xcode, this means you can no longer navigate by word or subword in:
- the filename input
- the source control commit sheet
- anywhere else you’d normally be able to navigate by word other than the editor
I assume this is a bug, and I presume it’s long-standing enough that Apple hasn’t bothered to find a new default shortcut for subword navigation that doesn’t conflict with the MacOS defaults!