5
$\begingroup$

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?

$\endgroup$
12
$\begingroup$

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.

$\endgroup$
9
  • $\begingroup$ Do you know where these things are documented? And one remark, under mac, the file is located in another subdirectory named "Macintosh". Thank! $\endgroup$
    – Dror
    Apr 10 '12 at 9:49
  • $\begingroup$ @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. $\endgroup$
    – Heike
    Apr 10 '12 at 9:59
  • $\begingroup$ 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. $\endgroup$
    – rcollyer
    Apr 10 '12 at 15:16
  • $\begingroup$ @rcollyer Have you tried restarting Mathematica after making changes to KeyEventTranslations.tr? $\endgroup$
    – Heike
    Apr 10 '12 at 16:22
  • 1
    $\begingroup$ For shift+home and shift+end use: Item[KeyEvent["Home", Modifiers -> {Shift}], "SelectLineBeginning"], Item[KeyEvent["End", Modifiers -> {Shift}], "SelectLineEnd"], $\endgroup$
    – Cantor
    May 8 '20 at 5:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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