# How to clear all output cells and run all input cells

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.

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 FrontEndFrontEndExecute's.

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

Item[KeyEvent["v", Modifiers -> {Control, Shift}],
FrontEndFrontEndExecute[{
FrontEndFrontEndToken["EvaluateNotebook"]
}]]

2. Use a keyboard shortcut to clear all output cells.

 Item[KeyEvent["w", Modifiers -> {Control, Shift}],
FrontEndFrontEndExecute[{
FrontEndFrontEndToken["SelectGeneratedCells"],
FrontEndFrontEndToken["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*"]],
]

4. Delete current cell with a keyboard shortcut.

Item[KeyEvent["x", Modifiers -> {Control, Shift}],
FrontEndFrontEndExecute[{
FrontEndSelectionMove[FrontEndInputNotebook[], All, Cell],
FrontEndFrontEndToken["Clear"]
}]]


References

• This is really good thank you. Just one more question how do I change them to work with macs? – AzJ Nov 10 '16 at 3:30
• 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" ) – AzJ Nov 10 '16 at 4:05
• @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). – user31159 Nov 10 '16 at 11:26
• @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. – user31159 Nov 10 '16 at 11:43
• @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.) – user31159 Nov 10 '16 at 11:58

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.

• 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. – AzJ Nov 9 '16 at 23:37
• @AzJ then you may want to look at this mathematica.stackexchange.com/questions/13978/… – ktm Nov 9 '16 at 23:38
• 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. – AzJ Nov 9 '16 at 23:52
• 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. – ktm Nov 9 '16 at 23:58

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.