Search code examples
tabssublimetext3indentationlowercase

Sublime Text 3 - Hitting tab doesn't add space, instead makes text lower case


If I were to type the following:

TEST

Then hit TAB, the code would now look like this:

test

I don't know what happened, but tab is not indenting anymore and changes the text on the current line to lowercase.

Any idea how to restore the TAB function?


Solution

  • One possible reason for this in the general case is that you have installed a third party package that's stolen the Tab key binding in order to perform it's own action, which in this case would be turning the prior word lower case.

    This will be the case if this behaviour holds true for any word that you happen to press Tab after. In that case the solution would be to find the package that's doing this and disable or reconfigure it.

    In your case I think the more likely cause for this is that in the file you're currently editing the word TEST appears, and you have the following setting turned on:

    // When enabled, pressing tab will insert the best matching completion.
    // When disabled, tab will only trigger snippets or insert a tab.
    // Shift+tab can be used to insert an explicit tab when tab_completion is
    // enabled.
    "tab_completion": true,
    

    When the setting is set to true (which is the default), pressing Tab will attempt to perform a tab completion, which considers not only snippets and completions but also words in the current buffer as well.

    In that case, if you were to enter the word test and press Tab at a point where the word TEST also appears in the buffer, it's considered a potential completion and will become the replacement.

    If this is the problem you would see similar behaviour by just entering t and pressing Tab, which would cycle through all of the T words in the buffer as possible completions.

    Assuming this is what's happening to you, one of the following should fix the problem for you:

    1. Set tab_completion to false in your preferences; this will disable the feature entirely everywhere

    2. Set tab_completion to false only in the settings of the specific file type that you're having the problem in; that would leave the feature enabled in the general case but stop it from occurring in the files that you don't want it to occur in.

    3. Use Shift+Tab instead; that key sequence will do what Tab normally does and insert a tab character even if Tab would try to do a completion.

    For #3 to work, make sure that you have this setting set as follows:

    // By default, shift+tab will only unindent if the selection spans
    // multiple lines. When pressing shift+tab at other times, it'll insert a
    // tab character - this allows tabs to be inserted when tab_completion is
    // enabled. Set this to true to make shift+tab always unindent, instead of
    // inserting tabs.
    "shift_tab_unindent": false,
    

    The default for this value is false, in which case as the comment mentions the binding will perform a tab unless you have multiple lines selected in which case it unindents instead.