nushell / reedline

A feature-rich line editor - powering Nushell
https://docs.rs/reedline/
MIT License
549 stars 152 forks source link

More granular config for triggering tab completions, and inserting completions #623

Open adamkpickering opened 2 years ago

adamkpickering commented 2 years ago

Related problem

I have tried using nushell as my main shell, and I would very much like to, but there is one thing that keeps me from doing so permanently. I come from using bash as my main shell, and the tab completion behaviour is very different between the two shells. Of course, different can be good, but in the case of tab completion I think nushell's implementation can be improved.

In bash, if there is a single string that matches what you have already typed (I'll call this the "single match" case), and you press tab, it automatically inserts that string. This is the same as nushell with quick_completions enabled. I like this behaviour.

However, if there are multiple strings that match what you have typed (I'll call this the "multiple match" case), the behaviour differs greatly. In bash, you press tab twice, at which point a list of all the strings that match are printed. Then you can use this list as a reference to know how much more you need to type until you get to the single match case.

For the multiple match case in nushell, if you press tab once, you are popped into a menu where you need to use the arrow keys and then enter to select the string you want. You can also continue typing to narrow the set of strings, but you always (unless you have quick_completions enabled) must press enter to get the string you want.

The thing I don't like about the nushell behaviour is that it requires me to do a mental context switch. In bash, all I have to think about is typing and then mashing tab and then maybe typing some more. In nushell if I do this, I enter "tab completion mode" and the meaning of the characters I type changes drastically. I end up entering all kinds of things I never intended to. It requires me to keep track of what mode I'm in. I find it very jarring. That's the first thing I want to highlight here.

The second thing I'd like to highlight (maybe this should be a separate issue?) is concerning the quick_completions key in the config. It seems that it affects two related but distinct bits of functionality. The first is when you're typing normally - with it enabled, you can press tab to insert a single match, if it exists. The second is when you're in tab completion mode - if you've continued typing to the point where there is a single match left, it will insert that string without the need to press enter if quick_completions is enabled. I like having the first one, but if I'm going to be using the tab completion menu I don't want it to insert anything unless I press enter.

Describe the solution you'd like

I would like more granular config regarding tab completions. I would have a key in the config for each of the following:

Describe alternatives you've considered

No response

Additional context and details

No response

elferherrera commented 2 years ago

I think this can be improved if quick completions can be called all the time and not only when you trigger the menu the first time

adamkpickering commented 2 years ago

I'm not sure what you mean?