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)

 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.

| improve this answer | |
  • $\begingroup$ Thanks, it works! Can you map any key that way? Where is this type of thing documented? $\endgroup$ – Rico Picone May 27 '14 at 1:43
  • $\begingroup$ 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") $\endgroup$ – mfvonh May 27 '14 at 1:57
  • $\begingroup$ 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. $\endgroup$ – Rico Picone May 27 '14 at 3:21
  • $\begingroup$ @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. $\endgroup$ – mfvonh May 27 '14 at 3:56
  • $\begingroup$ @RicoPicone Just took a stab at "block tab": see here $\endgroup$ – mfvonh May 27 '14 at 4:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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