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

Is there a way to set the tab key to simply insert the tab character in a notebook? I often find the sometimes mysterious "features" bound to that key detrimental.

share|improve this question
up vote 5 down vote accepted

You can try (for a single notebook)

 NotebookEventActions -> {{"KeyDown", "\t"} :> 
  NotebookWrite[SelectedNotebook[], "\t"]}]

or (for global application)

 FrontEndEventActions -> {{"KeyDown", "\t"} :> 
  NotebookWrite[SelectedNotebook[], "\t"]}]

Does this meet your needs? For me it had an effect in Input cells but didn't block autocomplete behavior, though if that's what's getting in your way it can be disabled in Preferences.

share|improve this answer
Thanks, it works! Can you map any key that way? Where is this type of thing documented? – Rico Picone May 27 '14 at 1:43
My pleasure. You can catch/handle single key presses, but not combinations like Ctrl + _ (it's been suggested that may be possible in the future). The docs aren't great, but there is some info in the section on EventHandler. If you are interested in mapping special keys (e.g. tab) you'll need to refer to them either using regex formats ("\t","\n",etc.) or in Mathematica-ese (see "Structural Elements and Keyboard Characters") – mfvonh May 27 '14 at 1:57
Thanks for the info. I thought I might try to implement a "block tab" of selected lines (which would be so nice). It's been requested here, but they didn't end up using the tab key. I'll have to explore more to find out why. – Rico Picone May 27 '14 at 3:21
@RicoPicone That's an interesting question. It also made me realize I mispoke: you can catch some combinations of keys such as Control (as LeonidShifrin shows in his answer). But I know that it is somehow limited (though I can't remember the details). I must be something like you can't capture the Alt key or Ctrl+Alt. – mfvonh May 27 '14 at 3:56
@RicoPicone Just took a stab at "block tab": see here – mfvonh May 27 '14 at 4:10

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.