8
$\begingroup$

I am new to mathematica and I am a little frustrated. There are a few things that I would like to do but I am finding difficult

  1. Use a keyboard shortcut to clear all output cells and run all input cells.
  2. Use a keyboard shortcut to run all input cells.
  3. Use a keyboard shortcut to clear all output cells.
  4. Use a keyboard shortcut to clear all variables and definitions from memory (a global clear).
  5. Delete current cell with a keyboard shortcut.

I also have no idea how to modify the system files to achieve the desired outcome so any help would be appreciated.

$\endgroup$

3 Answers 3

10
$\begingroup$

You can edit the file KeyEventsTranslation.tr to define new keyboard shortcuts. As mentioned by R.M. in this answer, you can copy this file from the $InstallationDirectory to the $UserDirectory and perform those changes in the latter (see the linked answer for details.)

Not all combinations of keys will work, since many are already bound by default. You can however comment the corresponding lines in the file to make them inactive and available for other actions.

The following codes are based on the keys "j", "v", "w", and "x", with the modifiers Control and Shift. These are not bound by default and work well on Windows.


  1. Use a keyboard shortcut to clear all output cells and run all input cells.

This can be obtained from points 2 and 3 below by combining the FrontEnd`FrontEndExecute's.

  1. Use a keyboard shortcut to run all input cells.

    Item[KeyEvent["v", Modifiers -> {Control, Shift}],
         FrontEnd`FrontEndExecute[{
            FrontEnd`FrontEndToken["EvaluateNotebook"]
         }]]
    
  2. Use a keyboard shortcut to clear all output cells.

     Item[KeyEvent["w", Modifiers -> {Control, Shift}],
          FrontEnd`FrontEndExecute[{
             FrontEnd`FrontEndToken["SelectGeneratedCells"],
             FrontEnd`FrontEndToken["Clear"]
         }]]
    
  3. Use a keyboard shortcut to clear all variables and definitions from memory (a global clear).

     Item[KeyEvent["j", Modifiers -> {Control, Shift}],
          KernelExecute[Remove["Global`*"]],
          MenuEvaluator -> Automatic
         ]
    
  4. Delete current cell with a keyboard shortcut.

    Item[KeyEvent["x", Modifiers -> {Control, Shift}],
         FrontEnd`FrontEndExecute[{
            FrontEnd`SelectionMove[FrontEnd`InputNotebook[], All, Cell],
            FrontEnd`FrontEndToken["Clear"]
        }]]
    

enter image description here


References

$\endgroup$
6
  • $\begingroup$ This is really good thank you. Just one more question how do I change them to work with macs? $\endgroup$
    – AzJ
    Nov 10, 2016 at 3:30
  • $\begingroup$ Also made the changes to the file but it still does not work. I Have a copy of the file here pastebin.com/wacMqMMq (note this is in the windows operating system and I changed the "v" shortcut to "m" ) $\endgroup$
    – AzJ
    Nov 10, 2016 at 4:05
  • 1
    $\begingroup$ @AzJ A coma is needed after an Item[...], if another follows. This can be seen from the syntax of the file. Here is a copy of the modified file: pastebin.com/StZuT4c3 (the paste expires in 24h). $\endgroup$
    – user31159
    Nov 10, 2016 at 11:26
  • $\begingroup$ @AzJ Control+Shift+m is already used to merge cells. I cannot find a way to supersede this binding, so no new definition associated to this combination is working on my side. $\endgroup$
    – user31159
    Nov 10, 2016 at 11:43
  • $\begingroup$ @AzJ I left m in the file, but it should be changed to, e.g, j. Otherwise, other modifiers on m could work. (I did not try that.) $\endgroup$
    – user31159
    Nov 10, 2016 at 11:58
5
$\begingroup$

Use a keyboard shortcut to clear all output cells and run all input cells.

Use a keyboard shortcut to clear all output cells.

I don't think a keyboard shortcut for this exists. Menu item Cell -> Delete all output is your best bet.

Use a keyboard shortcut to run all input cells.

CTRL+A -> SHIFT+ENTER in a notebook without any weird content.

Use a keyboard shortcut to clear all variables and definitions from memory (a global clear).

Keyboard shortcut doesn't exist for this, Clear["Global/`*"] or even quitting the kernel with Quit are your best options

Delete current cell with a keyboard shortcut.

What I normally do is arrow down once to go after the cell, press SHIFT+UP ARROW, and then press DELETE. Quick and easy in my day to day use.

$\endgroup$
4
  • $\begingroup$ This is useful but I was looking for something more in the vain of mathematica.stackexchange.com/questions/23285/… and mathematica.stackexchange.com/questions/29258/… and so on where the behavior is modified by editing files. $\endgroup$
    – AzJ
    Nov 9, 2016 at 23:37
  • $\begingroup$ @AzJ then you may want to look at this mathematica.stackexchange.com/questions/13978/… $\endgroup$
    – ktm
    Nov 9, 2016 at 23:38
  • $\begingroup$ Is there a general guide I can use to see how this works in general (i.e. editing the system files for mathematica). As I see these 'tricks' but I have no idea how to implement them. $\endgroup$
    – AzJ
    Nov 9, 2016 at 23:52
  • $\begingroup$ Unfortunately I think they are very intentionally poorly documented. Usually in complex situations I end up with what I need by combining content from a couple MSE questions and the official documentation. $\endgroup$
    – ktm
    Nov 9, 2016 at 23:58
0
$\begingroup$

Also I found this link useful in answering my own question Running Get["http://www.mertig.com/shortcuts.m"] adds a ton of useful shortcuts.

$\endgroup$

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.