Salomanuel
Salomanuel

Reputation: 955

Assign "Tab" (key) to "Tab" (indentation) in Sublime Text 3

While I'm handling Ruby files for Rails projects, I keep fighting the auto-complete
for example while writing

email:      params[:email],
password:

I press tab to add an indentation (I know Sublime Alignment, but sometimes I prefer to do it on my own) and it becomes password:key => "value",
I could press many spaces instead, but I don't like it and I already have a key for the tabs, I would like to use it

stuff I tried from old answers without success:

preferences file:

    "auto_complete": false,
    "tab_completion": false,
    "auto_complete_commit_on_tab": false,
    "auto_complete_selector": "source - comment",
    "auto_complete_size_limit": 4194304,
    "auto_complete_selector": "meta.tag - punctuation.definition.tag.begin, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc",

key bindings:

          // show autocomplete on tab, not automatically, commit on enter.
    "keys"   : ["tab"], 
    "command": "auto_complete", 
    "args"   : {"default": "\t", "exact": false},
    "context":
    [
        { "key": "setting.tab_completion", "operator": "equal", "operand": true },
        { "key": "preceding_text", "operator": "regex_match", "operand": ".*[^0-9][^\r ^\n ^\t ^\f]", "match_all": false },
    ], 


 "keys"      : ["tab"], 
 "command"   : "auto_complete", 
 "args"      : {"default": "\t", "exact": false},
 "context"   :
    [
        { "key": "setting.tab_completion", "operator": "equal", "operand": true },
        { "key": "preceding_text", "operator": "regex_match", "operand": "[][a-z]", "match_all": false },
    ], 

            //      method #2

  "keys"      : ["tab"], 
  "command"   : "insert", 
  "args"      : {"characters": "\t"}, 
  "context"   : 
        [
            { "key": "auto_complete_visible" }
        ]

        "auto_complete_triggers":
        [
            {
                "characters": "<",
                "selector": "text.html"
            }
        ],
        "auto_complete_with_fields": false,

Upvotes: 2

Views: 408

Answers (2)

Matt Pi
Matt Pi

Reputation: 795

in the key map, this is managed by the rule:

{ "keys": ["tab"], "command": "next_field", "context":
        [{ "key": "has_next_field", "operator": "equal", "operand": true }]
    },

Override this rule by

{ "keys": ["tab"], "command": "next_field", "context":[]}

Upvotes: 0

Keith Hall
Keith Hall

Reputation: 16105

You can set the following keybinding to ensure that Tab will always insert a tab character when the autocomplete popup is not open (and there is no selection, so you can still block indent text):

{ "keys": ["tab"], "command": "insert", "args": { "characters": "\t" },
    "context":
    [
        { "key": "auto_complete_visible", "operator": "equal", "operand": false },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
    ],
 },

if you want this only for Ruby on Rails, you can add the following context:

{ "key": "selector", "operator": "equal", "operand": "source.ruby.rails" }

Upvotes: 1

Related Questions