# How to overwrite key shortcuts?

It is very handy to have shortcuts for frequently used glyphs, e.g. [[, ]], <|, |>, and ->. I know already that we can do this by modifying KeyEventTranslations.tr located in

FileNameJoin[{
\$InstallationDirectory,
"SystemFiles",
"FrontEnd",
"TextResources",
"Macintosh"
}]


Working with US keyboard layout, I added the following to the file:

...

Item[KeyEvent[">", Modifiers -> {Control}],
FrontEndExecute[{
FrontEndNotebookWrite[FrontEndInputNotebook[],"\[AliasDelimiter]",After],
FrontEndNotebookWrite[FrontEndInputNotebook[],"->",After],
FrontEndNotebookWrite[FrontEndInputNotebook[],"\[AliasDelimiter]",After]
}]
],

Item[KeyEvent["[", Modifiers -> {Shift,Control}],
FrontEndExecute[{
FrontEndNotebookWrite[FrontEndInputNotebook[],"\[AliasDelimiter]",After],
FrontEndNotebookWrite[FrontEndInputNotebook[],"<|",After],
FrontEndNotebookWrite[FrontEndInputNotebook[],"\[AliasDelimiter]",After]
}]
],

Item[KeyEvent["]", Modifiers -> {Shift,Control}],
FrontEndExecute[{
FrontEndNotebookWrite[FrontEndInputNotebook[],"\[AliasDelimiter]",After],
FrontEndNotebookWrite[FrontEndInputNotebook[],"|>",After],
FrontEndNotebookWrite[FrontEndInputNotebook[],"\[AliasDelimiter]",After]
}]
],

...


This worked splendidly for the last two or three major releases of Mathematica. But now in version 12, precisely what Szabolcs anticipated here happened to me: Seemingly, new shortcuts

• Shift+Ctrl+.,
• Shift+Ctrl+[, and
• Shift+Ctrl+]

have been added, ruining my established workflow. Actually, I am not sure that these shortcuts are new, but starting with version 12, my former approach does work anymore. At least Shift+Ctrl+. seems to be remapped to something related to notebook cell selection. Shift+Ctrl+,, another shortcut that I remapped and that I use often, is already present in version 11.3 -- but the remapping worked well. So maybe the order in which the shortcuts are loaded when the FrontEnd starts has changed?

I don't use these shortcuts in the new built-in way; I'd rather prefer to overwrite them with my old settings because I #!@&ing don't want to relearn typing every time a new version is realeased!

I also found the "Shortcuts" package by Rolf Mertig, but as Rolf pointed out, it does not seem to work anymore (I have to admit that I have not tried it yet).

Has anybody found a robust, future-proof solution for this?

• Do you have a reference for the new shortcuts that have been introduced? – mikado Apr 27 '19 at 9:56
• I am still using version 10.1, but have you tried editing MenuSetup.tr? – Mr.Wizard Apr 27 '19 at 10:39
• @Mr.Wizard Thanks for the pointer. In MenuSetup.tr, I was able to find the line MenuItem["Extend Selection", "ExpandSelection", MenuKey[".", Modifiers->{"Control"}]], but that should not modify <kbd>Shift</kbd>+<kbd>Ctrl</kbd>+<kbd>.</kbd> or should it? Neither did I find any further remappings of ">" or "." that would fit the pattern... – Henrik Schumacher Apr 27 '19 at 11:10
• @mikado Hm. Actually I haven't found them documented yet. Shift + Ctr + , is another shortcut that I use often. It worked in version 11.3 but now I find it int the menu under "Insert" -> "Table/Matrix" -> "Add Column". And it was already there in version 11.3! I gues that WRI has changed the precendences of the loading of tr-files... – Henrik Schumacher Apr 27 '19 at 11:19
• I tried changing my modifier, and got a shortcut to work. I had used Item[KeyEvent["q", Modifiers -> {Shift, Option}], FrontEndExecute[FrontEndToken[SelectedNotebook[], "EvaluatorQuit", Automatic]]], to force the Kernel to quit. With version 12, when I typed the key sequence instead I saw the character Œ inserted. When I switched to use Modifiers -> {Shift, Control}, the shortcut started working. Is there any built-in variable that describes the search path for keyboard overrides? – Spencer Rugaber May 1 '19 at 13:22

KeyEventTranslations.tr started making problems in version 12, but just follow Mr. Wizard's advice. Some shortcuts you might like are already present in MenuSetup.tr, you can just add a few more in the same style. Find the line

MenuItem["Matching []", "InsertMatchingBrackets", MenuKey["]", Modifiers->{"Command", "Option"}]],


and add few more lines before or after

MenuItem["Rule \[Rule]",
FrontEndExecute[FrontEndNotebookWrite[FrontEndInputNotebook[],"\[Rule]", After]], MenuKey[">", Modifiers->{"Control"}]],
FrontEndExecute[FrontEndNotebookWrite[FrontEndInputNotebook[],"\[LeftDoubleBracket]", After]], MenuKey["[", Modifiers->{"Option"}]],
FrontEndExecute[FrontEndNotebookWrite[FrontEndInputNotebook[],"\[RightDoubleBracket]", After]], MenuKey["]", Modifiers->{"Option"}]],
FrontEndExecute[FrontEndNotebookWrite[FrontEndInputNotebook[],"\[LeftAssociation]", After]], MenuKey["[", Modifiers->{"Shift", "Control"}]],
FrontEndExecute[FrontEndNotebookWrite[FrontEndInputNotebook[],"\[RightAssociation]", After]], MenuKey["]", Modifiers->{"Shift", "Control"}]],


MenuItem["Matching \[LeftDoubleBracket]\[RightDoubleBracket]",
FrontEndNotebookWrite[FrontEndInputNotebook[],"\[LeftDoubleBracket]", After],
FrontEndNotebookWrite[FrontEndInputNotebook[],"\[RightDoubleBracket]", Before],

• Hah! Splendid! This works. I can even put my beloved \[LeftArrow] back onto Control+Shift+<. Have my accept, have my upvote! Thank you so much! – Henrik Schumacher May 11 '20 at 20:41
• Glad to help! If you have a lot of shortcuts to add and want to keep your Menu a bit organised, you can introduce a new grouping like this: inside Menu["Insert", { put Menu["My", { and add your shortcuts there, then close }],. Because every shortcut added to MenuSetup.tr` adds an item to your menu tabs. – Vladimir May 12 '20 at 13:11