0
$\begingroup$

This question already has an answer here:

I asked the following question before, but I do not think it has been fully answered.

By default, we use Shift+Enter to evaluate the current cell, and use Enter to get a new line. Is there a way to switch the two, i.e., use Enter to evaluate the current cell, and use Shift+Enter to get a new line (like in Maple)?

The answer is related to modifying the file "KeyEventTranslations.tr," part of which is

(* Evaluation *)
Item[KeyEvent["Enter"], "EvaluateCells"],
Item[KeyEvent["KeypadEnter"], "EvaluateCells"], 
Item[KeyEvent["Return", Modifiers -> {Shift}], "HandleShiftReturn"],
Item[KeyEvent["KeypadEnter", Modifiers -> {Shift}], "EvaluateNextCell"],    
Item[KeyEvent["Enter", Modifiers -> {Shift}], "EvaluateNextCell"], 
Item[KeyEvent["Return", Modifiers -> {Shift, Control}], Evaluate[All]],
Item[KeyEvent["Return", Modifiers -> {Option}], "SimilarCellBelow"], 
Item[KeyEvent["Escape"], "ShortNameDelimiter"], 

I tried many different ways to modify this file, but I never succeeded. I have many confusions about this file.

  1. The first item above is Item[KeyEvent["Enter"], "EvaluateCells"]. It seems that Enter is already used to evaluate cells, but it is not. I tried to modify this line as Item[KeyEvent["Enter"], "EvaluateNextCell"], Item[KeyEvent["Return"], "EvaluateCells"], and Item[KeyEvent["Return"], "EvaluateNextCell"], but in any case, Enter cannot evaluate the cell. (I am using a Windows laptop computer)

  2. If I switch EvaluateNextCell and Linebreak in Item[KeyEvent["Enter", Modifiers -> {Shift}], "EvaluateNextCell"] and Item[KeyEvent["Return"], "Linebreak"] (according to Jacob's answer), then both Shift+Enter and Enter are for a line break.

  3. What is difference between EvaluateCells and EvaluateNextCell? What does HandleShiftReturn mean? In a Windows laptop, does Return play a role?

  4. According to the link given by Szabolcs, we can evaluate the following in a notebook.

    SetOptions[EvaluationNotebook[], NotebookEventActions ->
    {"ReturnKeyDown" :>
    FrontEndTokenExecute["EvaluateCells"],
    {"MenuCommand", "HandleShiftReturn"} :>
    FrontEndTokenExecute["Linebreak"]}]
    

    This works for only one notebook in which the above command is evaluated, not for all notebooks. A puzzle to me is that even if we delete the above command, and reopen this notebook, the function of Enter and Shift+Enter is still switched (only for this notebook). I wonder where this information is stored.

Could you give a clear answer on how to modify the file "KeyEventTranslations.tr"?

$\endgroup$

marked as duplicate by Sjoerd C. de Vries, ciao, bobthechemist, Michael E2, m_goldberg Mar 18 '14 at 1:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ groups.google.com/d/msg/comp.soft-sys.math.mathematica/… $\endgroup$ – Szabolcs Mar 17 '14 at 20:02
  • 2
    $\begingroup$ SystemOpen@First@FileNames["KeyEventTranslations.tr", $InstallationDirectory, 8], items Item[KeyEvent["Enter", Modifiers -> {Shift}], "EvaluateNextCell"] and Item[KeyEvent["Return"], "Linebreak"]. Make a backup! $\endgroup$ – Jacob Akkerboom Mar 17 '14 at 20:11
  • $\begingroup$ On OS X, [Return] inserts a newline and [Enter], which is different key, produces evaluation. $\endgroup$ – m_goldberg Mar 17 '14 at 22:09
  • 1
    $\begingroup$ If you evaluate a cell, the cursor ismoved between the cells. And if there is another cell it will not be evaluated by "evaluateCells" but by "EvaluateNextCell" will. $\endgroup$ – Kuba Mar 28 '14 at 11:10
  • 1
    $\begingroup$ @renphysics, Regarding your flag, your update only mentions Szabolcs's link. I'll try to address the questions you ask in it: 1) It works only for that notebook because it explicitly sets it only for the EvaluationNotebook[]. You can set it for all notebooks by changing that to $FrontEnd 2) These settings are stored in the object's options and persists across sessions. See Options@EvaluationNotebook[]. $\endgroup$ – rm -rf Mar 28 '14 at 19:49

Browse other questions tagged or ask your own question.