为什么在 :vimgrep vim 命令中使用 **/* 递归搜索当前目录?
Why is **/* used to search recursively through current directory in :vimgrep vim command?
他们为什么使用双星号?
我已经阅读了 Vim 关于 vimgrep
的帮助,我查看了堆栈溢出和 vimcasts,虽然我发现很多人都说这个你是如何在当前目录中递归搜索的,我还没有找到关于为什么.
的解释
举个例子来说明一下。如果我想在我的当前目录中找到所有出现的 foo,我可以使用
:vim[grep][!] /{pattern}/[g][j] {file}
这样就变成了
:vimgrep /foo/ **/*
所以看看这个 grep 的 {file}
部分:
- 我理解是文件路径。
- 我知道星号 (
*
) 是通配符。
- 我知道正斜杠的作用是
目录分隔符。
我的具体问题是为什么它以
的格式出现
**/*
而不是
*/*
我曾尝试在几种不同的情况下使用 / 进行搜索,这似乎是在距离我当前目录恰好 1 层的任何目录中搜索任何文件,我认为这就是原因使用双星号。
即为什么是双星号?这是否通过一些我不完全理解的巧妙机制来指示 "I want you to search recursively",或者这只是一个用来表示 'search recursively' 的关键字?我完全不在乎吗?这不是 vim 的内置部分,而是 shell 的一部分? (这些部分不是我的实际问题,而是用来理解我的困惑,我的实际问题在上面)。
如果有任何方法可以改进我的问题,请告诉我,我是第一次提问。
简答:
双星号是 vim 内置关键字,它只是表示 'search recursively'。
它被使用,因为 vim 的创建者选择在这种情况下使用它。
更长的答案:
有两种不同的情况,其中使用 **
:文件搜索和其余。
Vim 帮助解释得很好。
对于 'rest',请参阅 :help wildcard
和 :help starstar-wildcard
:
来自 :help wildcard
:
** matches anything, including nothing, recurses into directories
和:help starstar-wildcard
指定:
Expanding "**" is possible on Unix, Win32, Mac OS/X and a few other
systems. This allows searching a directory tree. This goes up to
100 directories deep.
有关文件搜索,请参阅 :help **
或 :help starstar
。
引用相关部分(强调我的):
The file searching is currently used for the 'path', 'cdpath' and
'tags' options, for finddir() and findfile(). Other commands use
wildcards which is slightly different.
[...]
Downward search uses the wildcards '*', '**' and possibly others
supported by your operating system. '*' and '**' are handled inside Vim,
so they work on all operating systems.
[...]
'**' is more sophisticated:
- It ONLY matches directories.
- It matches up to 30 directories deep by default, so you can use it to
search an entire directory tree
- The maximum number of levels matched can be given by appending a number
to '**'.
他们为什么使用双星号?
我已经阅读了 Vim 关于 vimgrep
的帮助,我查看了堆栈溢出和 vimcasts,虽然我发现很多人都说这个你是如何在当前目录中递归搜索的,我还没有找到关于为什么.
举个例子来说明一下。如果我想在我的当前目录中找到所有出现的 foo,我可以使用
:vim[grep][!] /{pattern}/[g][j] {file}
这样就变成了
:vimgrep /foo/ **/*
所以看看这个 grep 的 {file}
部分:
- 我理解是文件路径。
- 我知道星号 (
*
) 是通配符。 - 我知道正斜杠的作用是 目录分隔符。
我的具体问题是为什么它以
的格式出现**/*
而不是
*/*
我曾尝试在几种不同的情况下使用 / 进行搜索,这似乎是在距离我当前目录恰好 1 层的任何目录中搜索任何文件,我认为这就是原因使用双星号。
即为什么是双星号?这是否通过一些我不完全理解的巧妙机制来指示 "I want you to search recursively",或者这只是一个用来表示 'search recursively' 的关键字?我完全不在乎吗?这不是 vim 的内置部分,而是 shell 的一部分? (这些部分不是我的实际问题,而是用来理解我的困惑,我的实际问题在上面)。
如果有任何方法可以改进我的问题,请告诉我,我是第一次提问。
简答:
双星号是 vim 内置关键字,它只是表示 'search recursively'。 它被使用,因为 vim 的创建者选择在这种情况下使用它。
更长的答案:
有两种不同的情况,其中使用 **
:文件搜索和其余。
Vim 帮助解释得很好。
对于 'rest',请参阅 :help wildcard
和 :help starstar-wildcard
:
来自 :help wildcard
:
** matches anything, including nothing, recurses into directories
和:help starstar-wildcard
指定:
Expanding "**" is possible on Unix, Win32, Mac OS/X and a few other systems. This allows searching a directory tree. This goes up to 100 directories deep.
有关文件搜索,请参阅 :help **
或 :help starstar
。
引用相关部分(强调我的):
The file searching is currently used for the 'path', 'cdpath' and 'tags' options, for finddir() and findfile(). Other commands use wildcards which is slightly different.
[...]
Downward search uses the wildcards '*', '**' and possibly others
supported by your operating system. '*' and '**' are handled inside Vim,
so they work on all operating systems.
[...]
'**' is more sophisticated:
- It ONLY matches directories.
- It matches up to 30 directories deep by default, so you can use it to search an entire directory tree
- The maximum number of levels matched can be given by appending a number to '**'.