Sublime Forum

How to: select previous auto-complete item

#1

Hello!

I am having a great deal of difficulty modifying some of the hotkeys in ST2. I would like to create a hotkey (or modify/discover the existing hotkey) for selecting the previous auto-complete item. More specifically, I want a hotkey to do exactly the opposite of what ctrl + space does when you have an auto-complete listing active.

This is the code for ctrl + space, as found within the default key bindings:

{ “keys”: “ctrl+space”], “command”: “auto_complete” },
{ “keys”: “ctrl+space”], “command”: “replace_completion_with_auto_complete”, “context”:

		{ "key": "last_command", "operator": "equal", "operand": "insert_best_completion" },
		{ "key": "auto_complete_visible", "operator": "equal", "operand": false },
		{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
	]
},

I’m not an experienced programmer, and I cannot understand this.

Also, whenever I input and save code into “Key Bindings - User”, I receive no effect. I’ve done this with code provided by others in this forum. Is there a common error in activating new “Key Bindings - User” commands?

Using win7 64bit.

Thank you!

1 Like

#2

I use the following set of key-bindings so that I can use ctrl-alt-right and ctrl-alt-left to cycle forward and back through the completions.

[code] { “keys”: “ctrl+alt+right”], “command”: “insert_best_completion”, “args”: {“default”: “”, “exact”: true} },
{ “keys”: “ctrl+alt+right”], “command”: “insert_best_completion”, “args”: {“default”: “”, “exact”: false},
“context”:

		{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
	]
},
{ "keys": "ctrl+alt+right"], "command": "replace_completion_with_next_completion", "context":
	
		{ "key": "last_command", "operator": "equal", "operand": "insert_best_completion" },
		{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
	]
},
{ "keys": "ctrl+alt+left"], "command": "replace_completion_with_prev_completion", "context":
	
		{ "key": "last_command", "operator": "equal", "operand": "insert_best_completion" },
		{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
	]
}[/code]

Check your key-bindings to ensure that you don’t have a spare, or missing, comma. Check the console Ctrl ’ (apostrophe) for any error message(s).

You could paste a copy of your current key bindings here if you want.

1 Like

#3

That’s great, thanks for the help @agibsonsw!

I don’t have time today, but I’ll test this tomorrow.

0 Likes

#4

Thank you again for that code, @agibsonsw. I do like the ability that that keycode configuration allows for, but unfortunately I don’t think can serve me in the way that I’m looking for right now.

So I must ask again: does anyone know how I can configure the exact opposite of the ctrl+space function? I really am just at a loss to figuring it out, I don’t understand how to reconfigure the JSON. My initial post explains exactly what I mean.

Thank you!

0 Likes

#5

No worries, but I think you need to clarify your request, as the exact opposite of Ctrl-Space could just mean Undo (Ctrl-Z), and ‘previous completion’ is also ambiguous.

0 Likes

#6

@agibsonsw

Sorry, what I mean is that, when I am coding, the auto-completion tab/popup emerges while I write, for example, “bac” in CSS to show me that I can auto-complete “bac” with the word background, etc etc. Now, to scroll down this auto-complete listing, I can use “ctrl+space”, and I will visually see that the next auto-complete option is highlighted. I can, at any point, press “enter” to select the currently highlighted auto-complete option.

I like this feature very much, but I cannot figure out how to get the auto-complete to highlight the option above the currently highlighted option. I can just continue to press “ctrl+space” until I go through the entire listing, but this can require many clicks depending on how many options are present. That’s what I meant by the opposite of “ctrl+space”. And obviously the hotkeys ‘could’ be configured to do this, since they can cause the highlighted option to move down, I just can’t decipher the JSON (the code I sent in my first message) adequately to recode it to highlight the previous selection instead of the following selection.

Sorry again, I’m trying to be as clear as possible. Thanks for sticking with me!

0 Likes

#7

Not sure how you would achieve this - I just use the Up and Down arrows or make use of the fuzzy-searching ability by entering letters that only appear in certain completions.

Perhaps someone else can advise you. Soz, Andy.

0 Likes