12
$\begingroup$

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[{
FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],"\[AliasDelimiter]",After],
FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],"->",After],
FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],"\[AliasDelimiter]",After]
}]
],

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

Item[KeyEvent["]", Modifiers -> {Shift,Control}],
FrontEndExecute[{
FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],"\[AliasDelimiter]",After],
FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],"|>",After],
FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],"\[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?

$\endgroup$
12
  • 2
    $\begingroup$ Do you have a reference for the new shortcuts that have been introduced? $\endgroup$
    – mikado
    Commented Apr 27, 2019 at 9:56
  • $\begingroup$ I am still using version 10.1, but have you tried editing MenuSetup.tr? $\endgroup$
    – Mr.Wizard
    Commented Apr 27, 2019 at 10:39
  • $\begingroup$ @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... $\endgroup$ Commented Apr 27, 2019 at 11:10
  • $\begingroup$ @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... $\endgroup$ Commented Apr 27, 2019 at 11:19
  • 1
    $\begingroup$ 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? $\endgroup$ Commented May 1, 2019 at 13:22

1 Answer 1

5
$\begingroup$

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[FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],"\[Rule]", After]], MenuKey[">", Modifiers->{"Control"}]],
MenuItem["Double bracket \[LeftDoubleBracket]", 
    FrontEndExecute[FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],"\[LeftDoubleBracket]", After]], MenuKey["[", Modifiers->{"Option"}]],
MenuItem["Double bracket \[RightDoubleBracket]", 
    FrontEndExecute[FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],"\[RightDoubleBracket]", After]], MenuKey["]", Modifiers->{"Option"}]],
MenuItem["Left association \[LeftAssociation]", 
    FrontEndExecute[FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],"\[LeftAssociation]", After]], MenuKey["[", Modifiers->{"Shift", "Control"}]],
MenuItem["Right association \[RightAssociation]", 
    FrontEndExecute[FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],"\[RightAssociation]", After]], MenuKey["]", Modifiers->{"Shift", "Control"}]],

I would even add

MenuItem["Matching \[LeftDoubleBracket]\[RightDoubleBracket]", 
    FrontEndExecute[{
        FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],"\[LeftDoubleBracket]", After],
        FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],"\[RightDoubleBracket]", Before],
    }], MenuKey["]", Modifiers->{"Command", "Control"}]],
$\endgroup$
3
  • 1
    $\begingroup$ 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! $\endgroup$ Commented May 11, 2020 at 20:41
  • $\begingroup$ 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. $\endgroup$
    – Vladimir
    Commented May 12, 2020 at 13:11
  • $\begingroup$ Ah, now it is much clearer to my how this works. Thank you once again! $\endgroup$ Commented May 12, 2020 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.