Sublime Forum

Making Tab completion in ST4 like ST3

#1

I’ve been very used to the ST3 tab completion, as I had it configured. I pressed tab and the word completed with something like it that was somewhere in the file (that was what I understood the behaviour to be). If it wasn’t the completion I wanted, I pressed tab again, and cycled through them. When I was happy I continued typing, and it inserted the new characters after the inserted text.

In ST4, this appears to have been replaced with tab popping up a distracting box over the top of the next line. This does nothing until I press tab again, which completes the word, and if that’s not the one I want, I have to press tab again, producing the distracting box, and then showing me the second word, and then I press tab a fourth time to accept that… and if it turned out I wanted the first completion, I … can’t get it because the next tab just inserts a tab.

The pattern I had of ‘press tab, start typing’ doesn’t work in ST4; it discards the tab completion that was in progress in the box, and just inserts the character I typed.

The ‘auto’ settings I have in my configuration file are:

"auto_close_tags": false,
"auto_complete": false,
"auto_match_enabled": false,

None of the configuration settings I can see in Preferences.sublime-settings appear to have any effect.

I can see that there’s a configuration for the ‘tab’ key in the keymap, which seems to have a bunch of differences to the ST3 settings, which were to use “insert_best_completion”. Adding these old settings to the configuration of the keymap appears ineffective. That is, adding:

{ "keys": ["tab"], "command": "insert_best_completion", "args": {"default": "\t", "exact": true} },
{ "keys": ["tab"], "command": "insert_best_completion", "args": {"default": "\t", "exact": false},
    "context":
    [
        { "key": "setting.tab_completion", "operator": "equal", "operand": true },
        { "key": "preceding_text", "operator": "not_regex_match", "operand": ".*\\b[0-9]+$", "match_all": true },
    ]
},
{ "keys": ["tab"], "command": "replace_completion_with_next_completion", "context":
    [
        { "key": "last_command", "operator": "equal", "operand": "insert_best_completion" },
        { "key": "setting.tab_completion", "operator": "equal", "operand": true }
    ]
},

to my default keymap has had the effect of making tab after a word do nothing at all. At this point I’m either going to turn off auto completion entirely, or revert to ST3.

Is there a way to restore the behaviour that works for me with ST4?

4 Likes

Tab autocomplete without the dropdown?
ST4 - can I change the Tab auto-complete behavior back to how it was in ST3?
#2

It may very well be that the experimental "mini_auto_complete" setting, when set to true in Preferences.sublime-settings, is supposed to be the successor of this minimalism workflow. However, it’s experimental and I don’t know the exact plans of @jps. Do note that you can’t “tab through the options” anymore with mini_auto_complete. Also, it’ll show a regular AC widget sometimes. I suspect this is due to a plugin enabling the sublime.DYNAMIC_COMPLETIONS flag when resolving its completions.

1 Like

#3

I’m pretty sure we are a minority here, but this is definitely a bit unexpected in case auto_complete is set to false even though technically ST3 was still completing/replacing the word with whatever was on top of that invisible list. I would also like to see an option for this in ST4. The main usage for me was to complete words in very close proximity. Of course sometimes the replacement was incorrect, but it was still useful for the most part. I also find popups distracting, plus sometimes that popup contains some really random stuff based on the context obviously, but sometimes that context can be pretty large.

3 Likes

#4

This is an issue for me as well. I use the PlainTasks plugin and I would push d + tab and be provided with an instant @due() snippet and press tab again to auto-enter the current date and time. Now, I have use the arrow keys to the bottom of the list every time.

0 Likes

#5

Issue for me too. I ONLY want to see the snippets, or at least see them at the TOP of the list, rather than having to scroll down now to get full completion (model fields etc), anmd I have little or no interest in all teh other suggestions. Is there any option available to set it back to how it behaved in ST3??

1 Like

#6

The experimental feature that @rwols suggested above sort of works:

"mini_auto_complete": true,

At least you get only the first suggestion and without a popup. Still not as fast as it used to be, when you were essentially gambling on what the first suggestion would be, but not as annoying as well.

1 Like

#7

I’ve also become accustomed to the way ST3 works and it’s the reason I can code significantly faster with ST3 than any other editor I’ve tried. You get kind of a feel of what the ST3 autocomplete would suggest based on what I’ve typed so far in the document and I’d adjust the number of tabs needed for certain things on the fly without thinking much about it on a subconscious level. I can tell due to how many accidental \t I’ve entered in ST4 before reverting back to ST3

It seems we only need a replace_completion_with_next_completion option to come back for ST4 and we would be golden

1 Like

#8

For the time being I have ‘solved’ this problem by downgrading to ST3 and marking the configuration with "update_check": false.

I’m working on the assumption that it will get fixed at some point either through a plugin or in the core, because there are a number of people annoyed by this.

This is annoying to me because, having upgraded I also saw the ‘License upgrade required’ notice, and so bought a license at that time - that’s a license that I now am not using, and it feels a little frustrating to a) not be able to upgrade because the editor is not usable in the way that I want, and b) having bought a license I cannot use.

0 Likes

#9

Well add me to the list of people who do not like the new autocomplete in ST4, I just made a new thread about this same thing before I found this one.

It’s now a two step process for autocomplete to work, TAB then ENTER. I’d like to go back to the way it worked before or a way to turn this 2nd step off.

0 Likes

#10

+1 this is an issue for me.

I am coming from emacs and figured ST4 would be the perfect time to jump ship to Sublime. This was one of the first annoyances I noticed, and from the thread it sounds like the ST3 behavior is more or less what I am used to (and very much enjoyed for its minimalism) from emacs. Would love to have this back in ST4!

0 Likes

#11

Btw do we have a thread about this on the issue tracker https://github.com/sublimehq/sublime_text ?

EDIT: Here is one https://github.com/sublimehq/sublime_text/issues/4421

1 Like

#12
import sublime
import sublime_plugin
import re

matching = []
last_choice = ''
lookup_index = 0
class HippieWordCompletionCommand(sublime_plugin.TextCommand):
	def run(self, edit):
		global last_choice
		global lookup_index
		global matching
		search_word_region = self.view.word(self.view.sel()[0])
		search_word_text = self.view.substr(search_word_region)

		if search_word_text != last_choice:
			lookup_index = 0
			matching = []

			search_word_parts = re.findall('([A-Z])?([^A-Z]*)', search_word_text)
			search_word_parts = [item for t in search_word_parts for item in t if item]
			# print(search_word_parts)

			# [matching.append(s) for s in reversed(word_list) if s not in matching and search_word_text in s and s != search_word_text]
			for word in reversed(word_list):
				found = False
				if word not in matching and word != search_word_text:
					for word_part in  search_word_parts:
						if word_part in word:
							found = True
						else:
							found = False
							break
				if found:
					matching.append(word)

			if not matching:
				for w_list in word_list_global.values():
					[matching.append(s) for s in w_list if s not in matching and search_word_text in s and s != search_word_text]

		else:
			lookup_index += 1
		try:
			last_choice = matching[lookup_index]
		except IndexError:
			lookup_index = 0
		finally:
			last_choice = matching[lookup_index]

		self.view.replace(edit, search_word_region, last_choice)


word_list_global = {}
word_pattern = re.compile(r'(\w+)', re.S)
class TextChange(sublime_plugin.EventListener):
	def on_init(self, views):
		global word_list_global
		# [print(a.file_name()) for a in views]
		for view in views:
			contents = view.substr(sublime.Region(0, view.size()))
			word_list_global[view.file_name()] = word_pattern.findall(contents)

		# print(word_list_global)
		

	def on_modified_async(self, view):
		global word_list

		first_half  = view.substr(sublime.Region(0, view.sel()[0].begin()))
		second_half = view.substr(sublime.Region(view.sel()[0].begin(), view.size()))
		word_list = word_pattern.findall(second_half)
		word_list.extend(word_pattern.findall(first_half))
		word_list_global[view.file_name()] = word_list
		# print(word_list)
// Keymap


	{ "keys": ["tab"], "command": "hippie_word_completion", "context":
	[
		{ "key": "has_snippet", "operand": false  },
		{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\w+", "match_all": true },
	]},

I wrote this crappy little plugin which basically bring backs the old completion method, there’s room for improvement obviously as I don’t code in python very much.

1 Like

#13

Can you post it on github so more people can see it and some possibly contribute?

0 Likes

#14

Feel free to post it, I am not very familiar with GitHub.

1 Like

#15

I’m reassured that Lightsout8008 has some prototype code that may be able to do what’s needed to make ST4 autocompletion useful to me. However, as the license I’ve bought is time limited, and I cannot use it right now, I’m going to request a refund until such point as I can use the editor - I’ll stick with ST3, I think, until there’s a working solution.

0 Likes