I am going to give this example in Python, but the concept is the same for every language
Suppose one has defined two variables
myvariablewithalongname_1=1
myvariablewithalongname_2=2
In a bash/python/ipython/julia console, if one starts typing myvariablewith
and then presses TAB, the text will be completed up to myvariablewithalongname_
and will show the options on how to finish the autocomplete. If there is only one option left, it completes with it.
Moreover, in the console, tab completion also works after a period, so doing np.
TAB will show all the options of numpy.
VS Code tab completion works in a different way. In the first case, after typing myvariablewith
and clicking TAB it will autocomplete to myvariablewithalongname_1
, pressing TAB again will circulate among the options (without ever showing all of them). In VS Code, tab completion does not work after a period, so np.
TAB will just add a tabular space. If one wants to see all the options, one has to press CTRL + Space.
VS Code also has a suggestion after special characters and a quick suggestion, but I find both of them very annoying. It creates too much noise for me.
What I want is pretty simple to describe:
- if there is only one option, tab completion should complete the option
- if there are multiple options, tab completion should display all of them (and ideally, complete the part of the predicate that matches all the options)
- this should work at any place except in places where one is just trying to include a tab, like in the beginning of a line or after a tab.
What I was able to achieve so far:
After a lot of try and error, I figured that including
{
"key": "tab",
"command": "editor.action.triggerSuggest",
"when": "atEndOfWord && textInputFocus && !inSnippetMode && !suggestWidgetVisible && config.editor.tabCompletion == 'on'"
},
in my keybinding allows me to get the suggestions to be triggered by TAB without having to press CTRL + Space. What it does not get me is:
- it shows me the suggestion even when there is only one suggestion
- it does not complete up to the predicate (at this point, more like a nice to have)
- it does not work after a period or any other character. The when condition “atEndOFWord” is what allows me to still maintain the customary behavior of tab in the beginning of a line.
Does anyone have a suggestion?
I tried figuring out by myself, but there is so little documentation. ChatGPT was not really helpfull. I keep imagining that someone else out there must have the same desire as mine, but I don’t even know how to look for it.
Raphael Chinchilla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.