0

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.

user2736738
  • 30,591
  • 5
  • 42
  • 56

3 Answers3

1

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.

skuroda
  • 19,514
  • 4
  • 50
  • 34
  • Thanks! This works, I just modified the regex slightly. `{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\s$", "match_all": true }` – Test Testington Mar 29 '15 at 11:18
0

A quick work around would be using Autohotkey if you are on windows. you can assign any keys to 4 spaces like below

`::
Send {Space 4} ; when pressed ` enters four times Space bar
Return
  • Thanks, but this is not what I want. My tab key works fine except when the autocomplete appears when I actually wanted to type a tab. I need the tab key to be "clever" and know when it's appropriate to show the autocomplete and when it's not. This could be determined by context. Either I am busy typing a word (should show autocomplete) or I am not (should type a tab). – Test Testington Mar 28 '15 at 22:56
0

Try this... Overrides tab key to function as indent key and insert tab char only

Preferences > Key Bindings

[
    { "keys": ["tab"], "command": "insert", "args": {"characters": "\t"} },
    { "keys": ["tab"], "command": "reindent", "context":
        [
            { "key": "setting.auto_indent", "operator": "equal", "operand": true },
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
            { "key": "preceding_text", "operator": "regex_match", "operand": "^$", "match_all": true },
            { "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true }
        ]
    },
    { "keys": ["tab"], "command": "indent", "context":
        [
            { "key": "text", "operator": "regex_contains", "operand": "\n" }
        ]
    },
    { "keys": ["tab"], "command": "next_field", "context":
        [
            { "key": "has_next_field", "operator": "equal", "operand": true }
        ]
    }
]