Sublime Forum

Autocomplete suggestions are not in expected order

#1

This is a tough one to explain but the sublime auto complete suggestions have been bothering me for a while after switching from TextMate, and I finally figured out what it is.

Reproduce:

Turn on tab_completion in your settings (I don’t use regular “auto_complete”)
Start with the following text:

[code]

test_really_long_thing
testThing
test
test_other_thing
test2_more
test3_more
test2
test3[/code]

Move your cursor to the top of the file above everything else.

Type “tes” then press tab to cycle through the autocomplete options.

Expected:
In order you should see:
test_really_long_thing, testThing, test, test_other_thing, test2_more, test3_more, test2, test3

In other words it should keep them in order because “tes” matches every single thing in the file and most likely test_really_long_thing is the first one you want to autocomplete because it is closest to you. This is also how TextMate behaves.

Actual
In order you will see:
test, test2, test3, testThing, test2_more, test3_more, test_other_thing, test_really_long_thing

I understand that Sublime Text2 here is trying to match the highest percent match based on number of characters, but in actual use that doesn’t make sense to me, and I find myself hitting tab a lot to get to the match I want. The point of autocomplete is to be able to type as little as possible and match as much as possible.

In this use case “test_really_long_thing” is the first thing in the list, the one that is closest to the cursor, but it takes 8 tab presses to select it vs. 1 in TextMate.

*Also as a side note I think there should be an option to prevent tab from autocompleting macros based on what you type. I don’t have a specific example but sometimes I will type something to try to get an autocomplete match and after a few tab presses it converts it to some function call and the tab key stops cycling through autocomplete options.

0 Likes

#2

Autocomplete is fuzzy. So ‘trlt’ matches test_really_long_thing. That should help shorten the number of keys you have to hit.

0 Likes

#3

That’s good to know, and will probably help, but that still doesn’t address what I mentioned.

In TextMate I can type t and hit escape and it will autocomplete to the closest thing that matches. Therefore it is 2 keypresses. In Sublime at the very least it takes 3 and in your example it takes 5 keypresses.

A lot of the time when I am using autocomplete I know that the method starts with something but I don’t know the whole method name.

So if there is an object with methods scattered around like

getAllThingsForUser()
getAllOtherThingsForUser()
getSetting()
get()

I want to be able to just type g or get and have it autocomplete based on how close it is to the cursor. I don’t know ahead of time the complete function call necessarily.

0 Likes

#4

I understand what your saying but it wouldn’t work since the autocomplete matches using fuzzy search. So people who use the normal autocomplete instead of just tab completion benefit more from this ordering rather than “closest position relative to cursor” ordering. Why not just have auto_complete enabled?

0 Likes

#5

So I guess what I’m proposing is that tab autocomplete should use proximity and start at the beginning of the string vs. fuzzy search.

The reason I don’t like the non tab auto_complete is because I find it annoying when it always pops up even if I don’t want to use it, and if it is enabled using a keyboard command then it is extra key presses to bring it up to begin with then you still have to find the match you want in the list, select it and hit tab or enter to confirm.

0 Likes

#6

Just wanted to point out for anyone who is curious I found a package that seems to make it work the way I expect it to:

github.com/alexstaubo/sublime_t … completion

0 Likes