50

When I highlight a block of code in Sublime Text 3 and press the Tab key, it doesn't indent the whole block like it used to. Instead, it deletes the highlighted code.

Anybody know how to fix this?

user3236406
  • 579
  • 1
  • 4
  • 10
  • Did you change any settings between when it used to work and now? Possible causes could include changes to your preferences, altering key bindings, or creating new macros assigned to `Tab`. – MattDMo Mar 13 '14 at 18:03

9 Answers9

192

This is a simple Alt+tab (Cmd+tab) issue

I have found that this happens when I've missed the "purchase this software" dialogue and have not dismissed it.

Alt-tab (or Cmd-tab on Mac) to check if there is a dialog window waiting for a response and dismiss it. This will resolve the issue.

As others have mentioned restarting Sublime will also resolve this issue because it is essentially dismissing the dialogue.

Dom
  • 2,057
  • 1
  • 14
  • 17
34

For anyone else who comes here from google, read this first:

SublimeText 2 (works for 3 as well) suddenly started doing this to me today without changing any settings. All I had to do was restart the program and it fixed itself.

Daniel
  • 1,403
  • 1
  • 14
  • 30
14

This is the default behavior for Sublime Text. If you select multiple lines it will indent but if you select single line (selection does not contain a \n), it will run insert_best_completion command and delete the selection.

The fix:

In your user .sublime-keymap add the following:

{ "keys": ["tab"], "command": "indent", "context":
    [
        { "key": "text", "operator": "regex_contains", "operand": "." }
    ]
},

This will make your tab key always indent. Not sure if it will conflict with auto-completion if you have it set up on Tab key.

Same goes for unindenting with shift+tab:

{ "keys": ["shift+tab"], "command": "unindent", "context":
    [
        { "key": "text", "operator": "regex_contains", "operand": "." }
    ]
},
Sergey Telshevsky
  • 12,077
  • 6
  • 55
  • 78
3

Similar to the answer by Dom above, it also happens when the upgrade message for sublime appears and is not in focus. I've also found that if you open Sublime enable another monitor then the upgrade message appears off screen too.

The only fix seems to be restarting sublime. This also re-centers the dialog box.

shoo
  • 41
  • 1
  • 3
  • Your post doesn't speak about fixing the issue. – Raju May 13 '16 at 13:57
  • Well that was my problem, thanks for the idea. spent 10 minutes figuring out whats wrong with my keyboard :D – Playdome.io Nov 25 '16 at 01:01
  • 1
    I had this issue and it was exactly as @shoo says...the purchase dialog was open behind the app. Once I closed the upgrade dialog, tab key worked again. Very strange. – Scott Apr 14 '17 at 18:24
  • "...it also happens when the upgrade message for sublime appears and is not in focus." - Yes! This was driving me nuts. Why is this _still_ an issue in '17... – Beepye Jul 05 '17 at 19:45
1

This was happening to me too, and it was due to the fact that my selected text appeared to be a block, but was actually a single line of wrapped text. By default ST3 will replace a single selected line with a tab character.

For me, it's more convenient to un/indent selections, whether they are multiple lines or not, so I added the following to my User-specific sublime-keymap file.

{ "keys": ["tab"], "command": "indent", "context":
  [
    { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true },
  ]
}
Mars Redwyne
  • 1,267
  • 13
  • 8
1

I figured out the issue when I click "tab" and check status bar in the bottom which should tell you why it happens.

After I found the related package, I just

  • Removed Emmet Style Refloctor package which causes the issue (not Sublime Text itself)
  • Restarted the Sublime Text

It works well now.

kuzey beytar
  • 3,076
  • 6
  • 37
  • 46
0

same thing happened to me. Just go to preferences->key bindings then in the user (right) keybindings add this:

[
     { "keys": ["tab"], "command": "indent" },      
     { "keys": ["shift+tab"], "command": "unindent" },
]

Then restart sublime and it should work fine!

Note: this does break the tab completing things but copying the tab defaults will fix this. Also if you use enter it works fine as well. Good luck!

0

You can check below points that can cause this issue

  • You may have sublime license popup open in background. just close it.
  • Any of your keyboard key is pressed then you can check by opening "on-screen keyboard" from start menu. (it'll show highlighted key if any key is pressed.)
0

It's because of the "Do you want to purchase/update" popup/alert window. Click on sublim text in your OS task bar if you don't see it then close it. Other frequent issue with that : scroll disabled.