# 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).

-
why not rebind it at the OS level if you're married to it? Also see this related question: stackoverflow.com/q/5808695 Looks like vim users are pretty anal about their bindings... ;) – R. M. Jun 29 '12 at 0:46
There are want to rebind caps-lock to esc; but I only want to rebind ctrl-f to esc (my caps-lock is bound to ctrl). Truth be told, all I need is a turing-complete keyboard mapping language, and I'd be happy. – user1602 Jun 29 '12 at 0:53
Changed title to reflect a more general problem, and added Q to customization wiki as perfect example. – István Zachar Jun 29 '12 at 8:32
You can use Autohotkey for a systemwise remap. It is easy as hell, and the script can be turned on/off on the fly anytime with a click (which is not true for changes made to KeyEventsTranslation.tr). – István Zachar Jun 29 '12 at 8:39

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[{
FrontEndNotebookWrite[FrontEndInputNotebook[],
"\[AliasDelimiter]", After]
}]],

-
Also, since you're editing your .tr file, you might as well include these shortcuts for 〚〛 (or Part) too, while you're at it, as these are very useful and commonly used – R. M. Jun 29 '12 at 1:06
I wonder, how easy is to maintain such changed system files as KeyEventTranslations.tr when someone changes to a new version of Mathematica and/or to a new computer? Can these customized files handled in a bunch? Would a software update revert these to default? – István Zachar Jun 29 '12 at 8:35
@IstvánZachar You can put a version of KeyEventTranslations.tr with your changes in $UserBaseDirectory/SystemFiles/FrontEnd/TextResources/Macintosh/ because this file is read before the KeyEventTranslations.tr under $InstallationDirectory an so survives new Versions. – Peter Breitfeld Jun 29 '12 at 9:33
@IstvánZachar As Peter said, the files in $UserBaseDirectory supersedes the installation files. In my answer too, I suggest modifying this file and not the installation file – R. M. Jun 29 '12 at 15:11 @PeterBreitfeld Like you suggested, I cpoied KeyEventTranslations.trand MenuSetup.trin $UserBaseDirectory\SystemFiles\FrontEnd\TextResources\Windows`. These were modified Mma10 files. But since then I'm not able to start Mm9 correctly. Where is my fault? – Phab Nov 25 '14 at 12:16