为什么Vim'标签中都存在./tags和标签。选项?

时间:2016-02-21 04:15:59

标签: vim

如果我在Vim中执行:set tags?,我会得到以下输出。

  tags=./tags,./TAGS,tags,TAGS

如果我在Vim中执行:help 'tags',我会收到以下文档。

                                                *'tags'* *'tag'* *E433*
'tags' 'tag'            string  (default "./tags,tags", when compiled with
                                |+emacs_tags|: "./tags,./TAGS,tags,TAGS")
                        global or local to buffer |global-local|
        Filenames for the tag command, separated by spaces or commas.  To
        include a space or comma in a file name, precede it with a backslash
        (see |option-backslash| about including spaces and backslashes).
        When a file name starts with "./", the '.' is replaced with the path
        of the current file.  But only when the 'd' flag is not included in
        'cpoptions'.  Environment variables are expanded |:set_env|.  Also see
        |tags-option|.
        "*", "**" and other wildcards can be used to search for tags files in
        a directory tree.  See |file-searching|.  {not available when compiled
        without the |+path_extra| feature}
        The |tagfiles()| function can be used to get a list of the file names
        actually used.
        If Vim was compiled with the |+emacs_tags| feature, Emacs-style tag
        files are also supported.  They are automatically recognized.  The
        default value becomes "./tags,./TAGS,tags,TAGS", unless case
        differences are ignored (MS-Windows).  |emacs-tags|
        The use of |:set+=| and |:set-=| is preferred when adding or removing
        file names from the list.  This avoids problems when a future version
        uses another default.
        {Vi: default is "tags /usr/lib/tags"}

我想知道为什么此选项中都包含./tags和'标记?

文档说When a file name starts with "./", the '.' is replaced with the path of the current file.所以./tags似乎与tags的行为相似,或者我错了?

此选项中./tagstags之间的区别是什么?

1 个答案:

答案 0 :(得分:3)

当前文件的路径不一定与当前工作目录相同。使用tags后一个目录,./tags,前者。差异在:h tags-option中解释:

When a tag file name starts with "./", the '.' is replaced with the path of
the current file.  This makes it possible to use a tags file in the directory
where the current file is (no matter what the current directory is).  The idea
of using "./" is that you can define which tag file is searched first: In the
current directory ("tags,./tags") or in the directory of the current file
("./tags,tags").

For example: 
        :set tags=./tags,tags,/home/user/commontags

In this example the tag will first be searched for in the file "tags" in the
directory where the current file is.  Next the "tags" file in the current
directory.  If it is not found there, then the file "/home/user/commontags"
will be searched for the tag.

例如,请考虑以下目录树:

.
├── project2
│   └── tags
└── project1
    └── tags

你这样做:

cd project1; vim ../project2/foo.c

然后首先使用project2/tags,然后project1/tags(假设您没有设置autochdir,或类似的恶作剧不起作用)。

相关问题