Is there a way to configure Mathematica so that the code does not move around while one is typing? It is driving me crazy and I can't see what I am typing as the code is being reformatted while typing.

This is standard notebook, V10. Here is a small animation to show the problem. This happens while I am changing some code, where I see other lines are moving based on what I type in a different line. This below is just an example. This happens in many other cases.

I once tried a code cell, but that caused many other problems, so I do not use Code cell anymore.

Is there a setting or some solution to prevent this? I am on windows 7.

enter image description here

Here is the actual code snippet above if needed.

 fileName = "ode" <> ToString[i] <> ".tex";
 PutAppend[TeXForm[ode[[i]]], fileName];
 res = DSolve[ode[[i]] == 0, y[x], x];
 PutAppend[TeXForm[res], fileName];
 , {i, 10}]
  • $\begingroup$ @LeonidShifrin Yes, as I mentioned that is a solution, but there are other problems with using Code Cells. For example, not allowed in a Demonstration style sheet. I also remember other issues with it, but can't remember exactly now what they are, I just know I had another problem using code cells. Thanks. $\endgroup$
    – Nasser
    Commented Jul 14, 2014 at 1:39
  • $\begingroup$ Ok, sorry, I didn't notice that you mentioned that. $\endgroup$ Commented Jul 14, 2014 at 1:42
  • 1
    $\begingroup$ If you like how code cells work, you can turn the autoindenting off for Input cells $\endgroup$
    – Rojo
    Commented Jul 16, 2014 at 15:58

1 Answer 1


If you want Mathematica to indent your code, then there is no complete way around it. You can of course turn indentation completely off and then there would be not shuffling anymore, but the automatic indentation is generally a good thing and you should not consider this way.

There is something you can do to minimize this shuffling, but you have to change the way you type code. This is btw a good thing, because you will be faster and you will make less errors. Assume you want to erase the PutAppend expression and then, you want to type it again.

enter image description here

Why doesn't my code jiggle at all? Because I don't wildly erase stuff. I mark the expression I want to erase by expanding the selection with Ctrl+.. If you delete code this way, you don't erase closing ] which confuses the indenter because it thinks the rest of the code is now in another scope.

Secondly, use Alt+] to insert a pair of [] (or Ctrl+Shift+}). Your braces need to be paired anyway and as long as you don't need to surround an expression by braces, you can always insert both at the same time. Again, by inserting paired braces, you keep the rest of your code consistent and the indenter won't touch it.

Final note: The shortcut for Check Balance plays in the same league as Extend Selection, only that it always extends the selection to the next level of matching braces. Try it out. Place the cursor anywhere inside your code and use Ctrl+Shift+B.

  • $\begingroup$ Thanks, but as I said this was an example, where I was copying and adding a large expression. I know that what you are showing are rules of thumbs to remember and follow to reduce this shuffling problem. Do you know of a more fundamental solution to allow one to code as they want and not have the code move around? Something like with Code cell but in a standard Input cell? I also need now to try Code Cell to see if it works with CDF's. I never tried that. Thanks for your hints $\endgroup$
    – Nasser
    Commented Jul 14, 2014 at 2:35
  • $\begingroup$ The problem is, that the indenter cannot be adjusted this way. Maybe turning it off completely is really an option for you, but then you have to do all the linebreaks and indents by yourself. Otherwise you will have you code aligned at the left margin. $\endgroup$
    – halirutan
    Commented Jul 14, 2014 at 2:46
  • $\begingroup$ +10 for the Alt+] alone $\endgroup$
    – seismatica
    Commented Jul 14, 2014 at 6:00
  • $\begingroup$ How do you deal with comments. Is there a shortcut for (* *) , you created one, or you just live with it (like I've been doing)? $\endgroup$
    – Rojo
    Commented Jul 16, 2014 at 16:00
  • $\begingroup$ I have been wrestling with this problem for a long time. I find it profoundly distracting when the code shakes randomly. Turning off auto-indenting is probably the best option. But notebooks should not really do it like this. Visual Studio manages indentations perfectly well without pushing the code hither and tither. As long as there is a red squiggly line to indicate a mismatched bracket or another error, there is enough visual assistance. I would much prefer to hit the tab key on my own. $\endgroup$ Commented Nov 16, 2017 at 22:35

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.