Skip to main content

customization - Rebinding keys to define new keyboard shortcuts


I've checked MathematicaPreferences, and poked around the options on the toolbar. However, I don't see a way to define new keyboard shortcuts in Mathematica.


I've used VIM for 10+ years, and I've rebound Ctrl+F to be Esc for the last decade or so. I would like to also use this shortcut in Mathematica, to have Ctrl+F be Esc, so hitting something like:


Ctrl+F S Ctrl+F


should give me capital Sigma.


Question: how do I define new keybindings in Mathematica?


(I have a CS background, so I'd prefer things that involve editing config files / writing scripts -- that would give me more power -- over clicking things in a GUI).



Answer



Since you want this functionality to be able to insert aliases using the EscshortcutEsc syntax, you can edit the KeyEventsTranslation.tr file to achieve this. Copy the following file:


$InstallationDirectory/SystemFiles/FrontEnd/TextResources/Macintosh/KeyEventTranslations.tr


or its equivalent on your system to $UserBaseDirectory/ (with the same directory tree) and add the following modifications after EventTranslations[{ in the file:


Item[KeyEvent["f", Modifiers -> {Control}],
FrontEndExecute[{
FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],
"\[AliasDelimiter]", After]
}]],

Comments