12

From Vim's help document (see: :help 'path'):

'path' String(default on Unix: ".,/usr/include,,")

-To search relative to the directory of the current file, use:

:set path=.

-To search in the current directory use an empty string between two commas:

:set path=,,

It seems that . and ,, have no difference in 'path' option. They both mean the current directory.

I cannot understand why we need to put both . and ,, to the path option. What is the difference between :set path=. and :set path=,,?

0

2 Answers 2

16

"Current directory" and "directory of the current file" are two different things.

The "current directory" is by default the directory in which you started Vim. You ask Vim what it is with :pwd and change it with :cd or :lcd or by setting the autochdir option. If you never change it, it will stay the same until you close the current session.

The "directory of the current file" is exactly what it claims to be. If the current file is in the "current directory", both have the same value. If the current file is in another directory, they have different values.

For path to be useful, it is necessary to address those two scenarios with . and ,,.

Example:

$ cd /foo/bar/baz
$ vim filename
:pwd                   -->  /foo/bar/baz
:echo expand("%:p:h")  -->  /foo/bar/baz
:e ../file
:pwd                   -->  /foo/bar/baz
:echo expand("%:p:h")  -->  /foo/bar
7

The directory of the current file and current directory are two entirely different things (that may, on occasion, have the same value).

Consider:

cd /tmp; vim /etc/bash.bashrc

Unless I have autochdir (or something similar) set, the current directory is /tmp, yet the directory of the current file is /etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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