Search code examples
idesublimetextsublimetext3keymaps

I want tab to insert a tab in Sublime Text but it activates the autocomplete


I am using Sublime CodeIntel which I like for the autocomplete, however it pops up and inserts words while I am trying to insert tabs. I want tab to always insert a tab unless the character before my cursor is a letter.

I reckon this could be done with a user keymap for the tab key to look at context, but I don't know how to do it.


Solution

  • Something like the following should work. You may need to play with the order of the key bindings. Add the following to your user key bindings

     {
        "keys": ["tab"], "command": "insert", "args": {"characters": "\t" }, "context": [
            { "key": "preceding_text", "operator": "regex_contains", "operand": "[^a-zA-Z]$", "match_all": true }
        ]
     }
    

    Note that I don't have SublimeCodeIntel installed, so unsure how it will behave with that.

    As a nice debugging tip, enter sublime.log_commands(True) into the ST console to see what command is being executed for a particular key binding. May be useful in confirming that the command is running as you expect.