Vim:在打开的缓冲区中搜索
我喜欢 Visual Studio 的一项功能是能够仅在打开的文件中进行搜索。例如,如果我最近对某些文件进行了更改,并且我想跟踪这些更改,我可能会搜索某个单词,但仅在这些文件中搜索,以避免获得大量必要的匹配项。
Vim 可以做到这一点吗?!我感兴趣的是能够打开我已更改的文件以便使用:
gvim `git diff --name-only`
然后在这些文件中搜索我想要的内容。
One features I like with Visual Studio is the ability to search in open files only. For example, if I recently did changes to some files and I would like to trace those changes, I might search for a certain word, but only in those files to avoid getting a large list of necessary matches.
Is this possible with Vim?! What I am interested in is being able to open the files I have changed so for using:
gvim `git diff --name-only`
then search those files for what I want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个很好的方法是使用 vim 的内部 grep 命令 (
:vim
):这将打开一个小窗口(称为
quickfix
),其中包含搜索结果和要打开的链接相应的文件(不必打开)。A nice way to do that is to use vim's internal grep command (
:vim
):This will open a small window (called
quickfix
) with the search results and links to open the corresponding files (they don't have to be open).如果您希望 vim 打开自己的缓冲区中的所有文件以查找与您的 diff 匹配的文件,您可以尝试以下操作:
git diff --relative --name-only
显示索引中已更改的文件但文件名相对于当前工作目录。grep -l pattern
将报告包含pattern
匹配的文件名。 (请注意,该模式只需存在于文件中,不存在于git diff
输出中。)POSIX
$()
而不是反引号使得可以使用嵌套命令。If you want vim to open up all the files in their own buffers for files that match your diff, you could try this:
git diff --relative --name-only
shows the changed files in the index but with filenames relative to the current working directory.grep -l pattern <list of files>
will report the filenames that contain a match onpattern
. (Note that the pattern just has to exist in the files, not in thegit diff
output.)POSIX
$()
instead of backticks makes using nested commands possible.