Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This counts as something of a basic question, but one for which I cannot find an answer. I checked the documentation, I checked google, I searched it here, I read a bunch of different things, but nobody seems to have an answer.

Basically, I'm very lazy, and I rarely feel like dealing with wrapping things in brackets if it can be avoided. Things like @ and // are very useful, but there are times when things just must be put in suitable brackets, which can get annoying when working around already written code. If only one could highlight the text and press a keyboard command and suddenly have that text wrapped in brackets...

But wait! In Basic Math Assistant there is a button that does exactly this! It's just quite cumbersome to use given that you need to have that assistant open and click on it, you might as well just do it by hand. Is there any way to get something like this to be done via a keyboard command or something similar?

share|improve this question
As a start, here's some code to do it. Then you need to assign it to a shortcut. I haven't tried to get this working myself, but it's a good starting point. – Szabolcs Oct 17 '13 at 0:39

Here is the answer given by Rolf Mertig that includes many additional shortcuts.

One of them Ctrl+t, evaluates whatever is stored in joker.m file (invoked by Ctrl+Shift+J).

There are already two examples, coincidentally the second one is exactly what you need!

Ok, so briefly:

  • Get[""]
  • reset Mathematica
  • use Ctrl+Shift+J to open joker.m file
  • uncomment the last commented part of script (in this case but in general just put whatever procedure you are after)
  • save,Ctrl+S, and close file.

Now, whenever you use Ctrl+T it will wrap selected part of code in []. You can modify joker.m to adjust it for your needs ofc.

share|improve this answer
correction: the joker.m file is opened using Ctrl + Shift + J. – andandandand Dec 2 '15 at 18:57
@andandandand Thanks! It was changed in the newest version. – Kuba Dec 2 '15 at 19:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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