I’m not especially familiar with plugins for Sublime or how to work with those yet, but I wanted to ask if anyone knew of a way I could change what happens when I press the left arrow key during autocomplete.
I’ve noticed that when I’m typing, I will sometimes want to select the second autocomplete option in the list, and I will try to hit “down” to select it, then “tab”, but occasionally my finger will accidentally hit “left” as well and the cursor will move before it tab completes.
So, for example, if I type “valu|” (the | here is to represent the cursor) and have the cursor after the ‘u’, and hit down to select “value_2” rather than “value_1” for autocompletion, but hit “left” by accident, the cursor will move to “val|u” and it will autocomplete as “value_2|u” which is. annoying.
It’s happened enough times to me that I would like to modify the code somehow to change this behavior, and I don’t think I’ve ever intentionally done this, as I can’t think of a time I’ve wanted to autocomplete and keep some duplicate letter at the end after. The way it works now doesn’t even change what the autocomplete options are to be based on just the characters before the cursor: If “valid_1” and “valid_2” were variables I had, it would still select “value_2” because of that ‘u’ that it isn’t even including in what it’s completing.
I would want it to either exit the autocomplete when I hit “left” like “esc” does, or have it erase that letter at the end when it completes, but I’m not sure how to make this a plugin. I’ll look into the documentation for Sublime more when I have time, but in case anyone knows an easy way to do this, or if anyone else had this same thought, could anyone share any pointers?
Is there a way to change the behavior of tab complete?
It seems that a possible solution that would not require a plugin would be to make left do nothing when the auto-complete menu is visible. Try pasting the following into your key bindings:
{ "keys": ["left"], "command": "noop", "context": [ { "key": "auto_complete_visible" } ] },
More importantly, you are facing this issue because a typical keyboard forces the user to lift the right hand and move it away from the home row to where the arrow keys are. Such movement is prone to error. Here are some things you could do. First, I use Tab to move down the auto-complete menu, Shift + Tab to move up, and Ctrl + Tab to select the entry you desire. Please see key bindings below.
{ "keys": ["tab"], "command": "move", "args": {"by": "lines", "forward": true}, "context": [ { "key": "auto_complete_visible" } ] },
{ "keys": ["shift+tab"], "command": "move", "args": {"by": "lines", "forward": false}, "context": [ { "key": "auto_complete_visible" } ] },
{ "keys": ["ctrl+tab"], "command": "commit_completion", "args": {"by": "lines", "forward": false}, "context": [ { "key": "auto_complete_visible" } ] },
Second, you can use the Vintage package that ships with ST. This package mimics the commands from Vim, and was such a game changer for me. Finally, there are ergonomic keyboards out there that allow for different layers. The user can set one layer for keyboard navigation without the need to move the fingers away from the home row. I hope this helps.