If I type :e foo/**/foo*.js and hit tab then vim replaces the *s with all possible suggestions in the filepath. What if I realized that I wasn't specific enough (there are too many results in autocomplete) and I want to go back from the autocomplete suggestions to :e foo/**/foo*.js

My wildmenu settings are:

set wildmenu
set wildmode=longest:full,full,full
set nowildignorecase

Is there a key that would let me get back to what I had before hitting tab?


I don't think so, but perhaps using list as wildmode would suit you more.

:set wildmode=list,full

See more in Is there a version of Vim or plugin with a Command Mode auto completion?

Also help for more details and examples

:help 'wildmode'
| improve this answer | |

After setting wildmode=full, shift-tab takes me back to the original regex. The wildmode documentation for full is

"full" Complete the next full match. After the last match, the original string is used and then the first match again.

Originally, my wildmode was wildmode=longest:full,full,full. To get back to the original regex I had to tab, tab, then shift-tab. The reason I had to do two tabs is because the first tab took me did the longest:full.

"longest:full" Like "longest", but also start 'wildmenu' if it is enabled.

Based on this documentation it looks like longest:full doesn't have an option to go back to the original regex. The second time I tabbed, it took me to full, which will use the original string at the end of the wildmenu. This is why a shift-tab would take me back to the original regex after two tabs.

| improve this answer | |

I just stumbled across this myself and argued to change the (in my opinion) wrong default for the 'wildmode' setting.

Anyhow, while discussing this, I was told, that CtrlP can be pressed to let you return to from where you completed. This allows to go back and change what will be completed. An alternative would be to hit ShiftTab, however that might not work in the terminal.

| improve this answer | |
  • Thank you. I didn't realize that Shift Tab would return from where I completed. It doesn't exactly take me back, but if I foo/**/foo* then tab, shift-tab, tab. It takes me back to foo/**/foo*. Would you be able to explain why it works this way? I assume it has something to do with having longest, then full in my wildmode settings. – user2453676 May 18 '18 at 19:47
  • sorry, I don't understand what your problem is here. – Christian Brabandt May 19 '18 at 17:39
  • @ChristianBrabandt I think <c-p> works as <s-tab>, so if you had done more than one <tab> then <c-p> wouldn't exactly let you get back to what you had. You'd have to keep pressing <c-p> to get back. I think yours is not the right answer here. – klaus May 21 '18 at 3:52
  • @user2453676 tab-completion actually works on a list that matches your initial regex(or something). You can then <tab> or <s-tab> through all these list. So, when you press <tab> from list element 0, you go to list element 1, and so on. If you press <s-tab> from list element 1, you goto list element 0, and if you again press <s-tab>, you goto list element -1, which is essentially the last element in the list. That's why it works the way it does in your question. The longest, full in wildmode are just flags to work the tab-completion according to your taste. – klaus May 21 '18 at 3:56
  • @EnanAjmain correct. I am not sure why you are saying it is not correct. <C-P> and <s-Tab> get you where your were before completing the commandline. And that was the question – Christian Brabandt May 21 '18 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.