1
$\begingroup$

In my computation I often use the command ClearAll["Global*"] to eliminate all the variables I have defined so far. But to input stroke by stroke is burdensome when you need to execute it so often. As a result, I am seeking to define a shortcut key which enables me to execute this command efficiently. It would be better if it can be incorporated into the init files.

Does anyone know how to do this?

$\endgroup$
8
  • 3
    $\begingroup$ I tend to Quit[] instead because it is guaranteed to erase every little thing. $\endgroup$
    – Roman
    Sep 8, 2021 at 6:27
  • $\begingroup$ A shortcut key always gets pressed accidentally. To task it with erasing all variables would be considered a sub-optimal GUI feature. $\endgroup$
    – Syed
    Sep 8, 2021 at 6:35
  • $\begingroup$ You may always define an alias like e.g.: 'cl:= ClearAll["Global*"] ' $\endgroup$ Sep 8, 2021 at 9:16
  • $\begingroup$ @DanielHuber But this will not work. Since issuing cl first time after it was defined, will also clear cl itself. So the definition is lost and have to be typed again and we are back to square one. $\endgroup$
    – Nasser
    Sep 8, 2021 at 9:26
  • $\begingroup$ Right, you must define it in a different context. $\endgroup$ Sep 8, 2021 at 9:29

1 Answer 1

3
$\begingroup$

In this post, we discussed adding another option for restoring stack windows, which it seems only works on windows. The process is the same, besides the command that should be executed.

Open this file (assuming you installed Mathematica on C drive):

"C:\Program Files\Wolfram Research\Mathematica\12.3\SystemFiles\FrontEnd\TextResources\Windows\MenuSetup.tr"

There are also MenuSetup.tr for other languages.

Find Menu["&Edit", and add this after Redo:

MenuItem["Clear All", KernelExecute[ClearAll["Global`*"];], MenuKey["C", Modifiers->{"Command","Shift","Control"}], MenuEvaluator -> Automatic],

The code uses ClearAll["Global`*"] to clear all the variables define in the Global context, feel free to change it. Also, I'm not sure whether Alt+Ctrl+Shift+C conflicts with other commands. I tried to pick a hard one.

enter image description here

If you found a solution for macOS, feel free to edit or comment on the post.

$\endgroup$
2
  • $\begingroup$ Thanks for your great help. I did as what you said but it did not work at first several attempts. My intuition told me maybe it was the problem of the lowercase letter in the shortcut key, since I noticed in other shortcut combinations the letter is always in uppercase as long as there is a modifier "Shift". So I tried to modify the "c" to "C" and it works since. $\endgroup$
    – AlbertLew
    Sep 9, 2021 at 3:12
  • $\begingroup$ @AlbertLew Thanks for the suggestion. $\endgroup$
    – Ben Izd
    Sep 9, 2021 at 4:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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