5

Is there a way to set the HOME and END keys on a Mac's keyboard to jump the cursor to the line's beginning and end respectively?

I tried to apply a global solution, as suggested for example here, but this didn't help. Is there a way to do it internally in mathematica?

F'x
  • 10,817
  • 3
  • 52
  • 92
Dror
  • 1,841
  • 17
  • 19

1 Answers1

12

The file KeyEventTranslations.tr which can be found in the directory $InstallationDirectory/SystemFiles/FrontEnd/TextResources/Macintosh couples key events to actions in Mathematica. The two lines that define the behaviour of Home and End are

Item[KeyEvent["Home"], "ScrollNotebookStart"],
Item[KeyEvent["End"], "ScrollNotebookEnd"],

To change the behaviour of these two keys you could replace "ScrollNotebookStart" and "ScrollNotebookEnd" to "MoveLineBeginning" and "MoveLineEnd", respectively.

To be on the safe side, you could copy the file to the directory $UserBaseDirectory/SystemFiles/FrontEnd/TextResources/Macintosh first and edit that file instead of the original in $InstallationDirectory.

Heike
  • 35,858
  • 3
  • 108
  • 157
  • Do you know where these things are documented? And one remark, under mac, the file is located in another subdirectory named "Macintosh". Thank! – Dror Apr 10 '12 at 09:49
  • @Dror I've corrected the directory. I don't think these things are documented very well. There is some information about the various files and directories in the installation tree in the entry tutorial/MathematicaFileOrganization in the Documentation Center but that's about it AFAIK. – Heike Apr 10 '12 at 09:59
  • Putting KeyEventTranslations.tr in $UserBaseDirectory/.../Macintosh wasn't picked up on my system. I'll continue to poke at it and see if I can figure out where I should put it, but in the meantime, if you come up with something, please post an update. – rcollyer Apr 10 '12 at 15:16
  • @rcollyer Have you tried restarting Mathematica after making changes to KeyEventTranslations.tr? – Heike Apr 10 '12 at 16:22
  • Absolutely. I made the change, saved, shut-down mma, and restarted. – rcollyer Apr 10 '12 at 17:03
  • This is somehow outdated, but: http://reference.wolfram.com/legacy/v5/FrontEnd/FrontEndTokens/ seems to contain relevant information. – Dror Apr 11 '12 at 12:15
  • Found the issue: mma saved it as a .txt file not .tr! Works now. – rcollyer Apr 12 '12 at 02:38
  • In case anyone else visits this answer, be sure not to inadvertently change straight quotes " to curly quotes “ ”. I edited the .tr file in TextPad and this happened, causing an error on Mathematica startup. – Steve Kass Nov 14 '16 at 00:01
  • 1
    For shift+home and shift+end use: Item[KeyEvent["Home", Modifiers -> {Shift}], "SelectLineBeginning"], Item[KeyEvent["End", Modifiers -> {Shift}], "SelectLineEnd"], – Cantor May 08 '20 at 05:47