Sublime Forum

Keybinding changes to make ctrl+] have effect even on an empty line

#1

problem:
currently if you place your caret on an empty line and press ctrl+], nothing happens.
there are various reasons for which one might want SOMETHING to happen in this kind of situation, e.g. for a tab character to be inserted
in my own case, i often use sublime to compose plain text (“thinking out loud”) rather than do programming. having a single key that will ALWAYS “shift the line to the right” (to make clear the structure of your thoughts) is very convenient. currently there’s no such single key, because pressing ctrl+] at the beginning of line does nothing;

solution
add the following keybinding:

{ "keys": ["ctrl+]"], "command": "insert_snippet", "args": {"contents": "\t"}, "context":
	[
		{ "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true },
		{ "key": "preceding_text", "operator": "regex_match", "operand": "^$", "match_all": true },
	]
},

(i myself then use Autohotkey to map [tab] to [ctrl+l], as i’m more accustomed to use (shift)tab to shift lines right and left … )

1 Like

#2

Thanks, just what I was looking for. This version is slightly more comprenensive.

{ "keys": ["ctrl+]"], "command": "insert", "args": {"characters": "\t"}, "context":
    [
        { "key": "popup_visible", "operator": "equal", "operand": false },
        { "key": "overlay_visible", "operator": "equal", "operand": false },
        { "key": "auto_complete_visible", "operator": "equal", "operand": false },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true },
        { "key": "preceding_text", "operator": "regex_match", "operand": "^$", "match_all": true }
    ]
},
1 Like