Here are two simple but extremely convenient keyboard shortcuts that I've used for years.
- This post is a favor to all my friends who type slowly (like me)
- These shortcuts simply create a pair of brackets containing a template placeholder as the current new selection
- Essentially, it's just a stripped-down version of the bulky (Command + Shift + K + Up/Down Arrow + Enter) completion
Favorite Shortcut #1: Autocomplete single brackets by pressing CommandKey + [
Favorite Shortcut #2: Autocomplete part brackets by pressing CommandKey + ]
How to set them up
On MacOS, first make a backup of the following file, in case you break it:
FileNameJoin[{$InstallationDirectory, "SystemFiles/FrontEnd/TextResources/Macintosh/KeyEventTranslations.tr"}];
On my machine this path resolves to: "/Applications/Mathematica.app/Contents/SystemFiles/FrontEnd/TextResources/Macintosh/KeyEventTranslations.tr"
Then, preferably in a non-Mathematica editor (e.g. Sublime), open the above file and copy-and-paste these following code into the list inside EventTranslations
. For the first shortcut:
Item[KeyEvent["[",Modifiers->{Command}],FrontEndExecute[{FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],"[\[SelectionPlaceholder]]"],FrontEndToken["MovePreviousPlaceHolder"]}]]
And for the second (of course making sure they are separated by a comma):
Item[KeyEvent["]",Modifiers->{Command}],FrontEndExecute[{FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],"\[LeftDoubleBracket]\[SelectionPlaceholder]\[RightDoubleBracket]"],FrontEndToken["MovePreviousPlaceHolder"],FrontEndToken["MovePreviousPlaceHolder"]}]]
Finally, restart Mathematica, and presto, they should both be working. And to remove the shortcuts, simply remove those items or replace the .tr file with the backup.