TLDR. howto change vim path/file name search algorithm from cyclic autocompletion to incremental autocompletion. (like when autocompleting file paths in ubuntu terminal).
When opening a new file for editing in vim, for example using :vsp
or :tabe
the algorithm used when pressing the tab
key to predict the next part of the path/file for the targeted file, has inconvenient behavior that I would like to change.
For example, i have a directory with three files:
/one.txt
/onetwo.txt
/onetwothree.txt
When attempting to open onetwothree.txt
from a vim instance opened in the same directory, I would type :tabe o
then press the tab
key and vim will autocomplete the file name/path, to :tabe one.txt
. I must then press tab
again to change the autocomplete to :tabe onetwo.txt
and then again a third time to get :tabe onetwothree.txt
, before pressing enter
to open the file. (algorithm 1) The tab
algorithm has the behaviour of cycling through the complete path/file names one by one.
In the ubuntu terminal the search behaviour is much better and works that typing :tabe o
the pressing tab
will only partially autocomplete to give you :tabe one
. Then typing t
followed by tab
again will autocomplete from :tabe onet
to :tabe onetwo
and then pressing t
and tab
again will autocomplete from :tabe onetwot
to :tabe onetwothree.txt
. (algorithm 2) The tab
algorithm has the behaviour of partially completing the path/file name.
With the first algorithm the behaviour of pressing tab
to cycle through the complete path/file names one by one can be inconvenient when working with lots of files. In the second algorithm shown used by the ubuntu terminal tab
autocomplete has the behaviour of partially completing the path/file name and allows one to complete the path quickly and accurately.
I realise in this trivial example it takes two more key presses with the second algorithm, but in the non-trivial examples with many files cycling through every option is painful.
How can I change the filepath search algorithm? Is there a setting in the .vimrc
that specifies it?
You will need to enable :help 'wildmenu'
:
set wildmenu
and adjust its behaviour with :help 'wildmode'
:
" just an example
set wildmode=longest,list