# Can tab just mean “insert tab character”?

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.

-

You can try (for a single notebook)

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


or (for global application)

SetOptions[\$FrontEnd,
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.

-
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