40

Recently switched to Textmate on Mac for coding. On PC when ever I want to tab in or out a block of code I just highlight and press tab or shift+tab to move it in our out. It's very useful when you are adding an extra loop or conditional statement to a block of code to keep everything tidy and neatly indented.

On Textmate however when I try this it just replaces my selected text with a tab. So is there a way to do tab and de-tab lines of code in textmate?

Derek Organ
  • 8,323
  • 17
  • 56
  • 75

4 Answers4

79

Indent: Alt+Tab

Un-Indent: Shift+Alt+Tab

David Antaramian
  • 4,145
  • 1
  • 23
  • 16
8

the hotkey is command-left bracket to move left and command-right bracket to move right (the buttons next to 'p')

heres a link to more hotkeys and such http://projects.serenity.de/textmate/tutorials/basics/

Josh
  • 4,427
  • 5
  • 28
  • 27
  • I can't find that anywhere in those docs. I find the documentation for textmate horrible in general. – Derek Organ May 31 '10 at 15:29
  • Textmate calls it "Shift left" (= un-indent) and "Shift right" (= indent). You'll find it under these names in the doc and in Textmates' "Text" menu. – Alexander Klimetschek Jan 07 '11 at 12:43
  • cmd+[ is easier to hit than shift+alt+tab ! (sadly on my custom remapped dvorak layout I need to press a shift as well... still a pretty decent option +1) – PatrickT Mar 06 '18 at 06:47
  • On a non-american keyboard layout the backet symbol may be hard to reach. – neoneye Aug 02 '20 at 11:10
6

You can use Shift+Tab to decrease indent; You just need to make and assign a macro. You can reuse this technique to accomplish a great many things.

  1. Enter some text, and intend them, this is mostly for feedback.

  2. Click the Record Macro Button

Click the Record Macro Button

  1. Use ++ (aka; Shift + Option + Tab) to decrease the indentation.

  2. Click the record button to stop recording the macro.

  3. Use the Edit menu or ++M to save your macro;

    Edit -> Macros -> Save Macro

  4. Saving will prompt you to create a new bundle*, or add your macro to an existing bundle.

  5. Add a Key Equivalent by clicking in the field and pressing +

  6. Your bundle-macro should look like the one below, simply Save and you're done! TextMate will now decrease indent on +

Completed Macro

*: (as noted by u/PatrickT) Sadly the create new bundle functionality has not yet been implemented, and you must choose to add to an existing bundle. You can still create a bundle via Bundles -> Edit Bundles then Command + N.

Graham P Heath
  • 7,009
  • 3
  • 31
  • 45
  • 1
    Seems promising! At step 2, you need to click on the red button to stop recording, before proceeding to step 3. At step 5, I chose "new bundle" at which point I got a message saying it was not supported. That's where I left it... – PatrickT Mar 06 '18 at 06:51
  • 1
    @PatrickT That is an unfortunate message, the bundle system is a WIP, but all you have to do is to choose an existing bundle. You can still create a bundle via Bundles -> Edit Bundles then Command + N. – Graham P Heath Mar 06 '18 at 23:10
  • 1
    Thanks for your reply! does it mean that I need to repeat this action for as many bundles as I use or is there a way to do it only once? (from my recollection the bundles are associated with a particular language, since I use about 10 or so, I was afraid I'd have to do that 10 times) – PatrickT Mar 07 '18 at 08:11
  • 1
    @PatrickT You only need one, as is this is effective everywhere, if you wanted to limit it you'd use the Scope Selector field. – Graham P Heath Mar 07 '18 at 15:52
  • 1
    Very kind of you to have taken me by the hand all the way! This worked great. I also added the TAB key for ``shiftRight`` in the same manner as above. I saved it under the R bundle, but I was indeed able to use it with a ``.py`` script. The steps will not be easy to remember, but I know I can always come back here for a step-by-step guide. Thanks a lot!! – PatrickT Mar 07 '18 at 17:14
  • Thank you very much! Works like a charm. – nelsonspbr Apr 08 '20 at 17:57
3

As an alternative, you can change the keybindings, see Link

Here is what I did:

  • Install Link
  • Go to File -> Open -> User Key Bindings, this will create/edit ~/Libary/KeyBindings/DefaultKeyBinding.dict
  • Add a binding, for the action enter shiftRight: (indent) manually (this is a TextMate specific action and not in the pre-populated actions list)
  • Choose a shortcut, I used cmd+alt+right
  • Do the same for the action shiftLeft: (un-indent, I used cmd+alt+left)
  • Save and then restart TextMate

I used a shortcut with arrow keys as my right hand is already on the arrow keys when I am selecting multiple lines, so this is a good fit.

The reason why I did it was because I have a german keyboard and alt+tab/alt+shift+tab don't work for me since I am using Witch for app-switching using these exact shortcuts.

EDIT: cmd+alt+left/right don't work when you have multiple tabs open, as they are used for navigate to next or previous tab in TextMate... seems this cannot be changed or overridden (I tried Setting Shortcut Keys in Textmate). Looking for an alternative shortcut now.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Alexander Klimetschek
  • 3,585
  • 31
  • 36
  • I added \t and $\t to rightShift/leftShift, but unfortunately it only works when I have lines highlighted. Is there anyway to make it work on the current line the cursor is on when no lines are highlighted? – Nick Sotiros Mar 11 '15 at 02:28
  • The cocoabits website looks abandoned, is this the new place? https://docs.unrealengine.com/en-US/Engine/UI/KeyBindings/index.html – PatrickT May 24 '20 at 01:10
  • No, Unreal is a game :-) This might be a place to download that: https://de.freedownloadmanager.org/Mac-OS/KeyBindingsEditor-KOSTENLOS.html But I am sure there are other, newer solutions to edit the macOS keybindings. – Alexander Klimetschek May 24 '20 at 08:08