When I try to open a file in Vim (Linux) for editing, when I press TAB, Vim autocompletes filename only with filenames from the current directory. However, having searched on the Web, I suppose that from version 7 Vim should support bash-like filename autocompletion using filenames from all the directories in the search path.
Say, there is a file file1
in a directory dir1
(which directory is also in the environment variable PATH).
I type the following commands in Vim:
set path=/dir1
set wildmode=list:longest
And then, when I type:
:e fil<TAB>
The filename is not autocompleted. How to enable this feature in Vim?
Tab-completion works. You just expect it to do something it is not actually supposed to do.
:e[dit]
and its siblings (:sp[lit]
, :vs[plit]
, :tabe[dit]
) don't use the path
option at all, no matter what version of Vim you have.
Use :fin[d] fil<Tab>
instead (and :sf[ind]
, :vert sf[ind]
, :tabf[ind]
).
Use set path=/dir1/**
to make :find
recursive.
See :help 'path'
and :help :find
.
edit
It is generally considered "good practice" to start Vim from the root of your project:
$ cd /path/to/project
$ vim somefile
The main advantage being that it sets Vim's "current directory" to a usable value that allows you to browse your project relatively easily or use external programs on your project in a clean and intuitive way.