Vim 搜索所有现有缓冲区 [英] Vim searching through all existing buffers

查看:43
本文介绍了Vim 搜索所有现有缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

处理单个文件时,我习惯于:

When dealing with a single file, I'm used to:

/blah
do some work
n
do some work
n
do some work

假设现在我想在 Vim 中加载的所有缓冲区中搜索某种模式,对它们做一些工作,然后继续.我在此工作流程中使用哪些命令?

Suppose now I want to search for some pattern over all buffers loaded in Vim, do some work on them, and move on. What commands do I use for this work flow?

推荐答案

我有以下映射(受 Vimperator 启发)可以更轻松地切换上一个/下一个缓冲区.

I have the following mappings (inspired by Vimperator) that make switching previous/next buffer easier.

nmap <C-P> :bp<CR>
nmap <C-N> :bn<CR>

这对 'n' 非常有效.当您处理完文件后,只需在再次按 n 之前按 CTRL-n 即可在下一个缓冲区中搜索.重做,直到完成所有缓冲区.

This works really well with 'n'. When you're done working with your file, just hit CTRL-n before hitting n again and you're searching in the next buffer. Redo until you're through all buffers.

处理多个文件的另一种方法是参数列表.

Another way of working with many files is the argument list.

它包含在您启动 vim 时作为参数传递的任何文件(例如:vim someFile.txt someOtherFile.py).[括号]内的文件是当前文件.

It contains any files passed as parameters when you started vim (e.g: vim someFile.txt someOtherFile.py). The file within [brackets] is the current file.

:args
[someFile.txt] someOtherFile.py

:n 将带您到列表中的下一个文件,而 :N 将带您返回.您还可以使用 :argadd 添加到 argslist,或使用

:n will bring you to the next file in the list and :N will bring you back. You can also add to the argslist with :argadd, or create a new args list with

:n some.py files.py you.py want.py to.py work.py with.py
or to open all *.py files recursively from some project.
:n ~/MyProjects/TimeMachine/**/*.py

args 列表也适用于宏(请参阅 :help q),如果您对文件有类似的更改.只需在第一个文件上录制宏,以 :n 结束以移动到下一个文件,然后停止录制.

The args list work well with macros too (see :help q), if you have similar changes to your files. Just record your macro on the first file, finish with :n to move to the next file, and stop recording.

qq/searchForSomethingAndDoStuffOrWhatever:nq

然后在所有文件 (6@q) 中运行您的宏,确保一切顺利,然后以 :wall 结束.

Then run your macro through all files (6@q), have a look to make sure everything went well, and finish with a :wall.

这有点取决于你想做什么.如果您在许多文件中只有一个完全相同的更改(并且这些是您加载的唯一文件),我也喜欢 :ba (:tabdo sp) 命令.速度非常快,您可以看到发生了什么.

It kinda depends on what you want to do. If you just have one change that is exactly the same across many files (and those are the only ones you have loaded), I also like the :ba (:tabdo sp) command. It's very quick and you can see what's happening.

如果你打开了一堆缓冲区,你可以加载你想要在其中工作的文件,每个文件都在一个窗口中,并对所有文件执行正则表达式.

And if you have a bunch of buffers open, you can load up the files you want to work within, each in a window, and do a regexp on all of them.

CTRL-w v :b someFile
:sp anotherFile
...
:windo :%s/foo/bar/g

我真的推荐 FuzzyFinder,它让你打开文件时更轻松.

I really recommend FuzzyFinder, it makes your life a lot easier when opening files.

http://www.vim.org/scripts/script.php?script_id=1984

MMmmmmmm VIM 很好!好性感!:)

MMmMmmmm VIM IS NICE! SO SEXY! : )

这篇关于Vim 搜索所有现有缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆