在 Vim 中导航一系列文件
当修改代码时,我发现我经常需要浏览数十个文件才能更改最简单的内容。例如,假设我有一个函数 pretty_print
,我将其更改为符合驼峰式大小写 prettyPrint
。现在我想浏览文件 apple1.js
到 apple99.js
,可能还有一些 orange.js
文件。 Vim 有没有快速的方法来做到这一点?
注意:这不是我可以自动化的事情,我实际上需要自己进去修改代码。
我知道我可以执行 :b
,但是,尽管它支持名称完成/模式匹配,但我认为该模式不会被保留。
例如,如果我这样做
:b apple*.js
并点击选项卡,我会得到
:b apple1.js
,但是如果我重新访问该函数(通过按 :
+ upArrow 或 q:
),那么如果我点击选项卡它不会转到
:b apple2.js
我想要的是指定诸如
:b apple*.js
编辑文件之类的内容,然后当我输入 :w
时,它会移动到下一个缓冲区。我宁愿留在 Vim 中,不想出来,输入 vim apple*.js
,返回 Vim,然后使用 :x
命令。我意识到这是可行的,但我仍然需要所有其他文件,以防万一我想要,例如在标签之间跳转。
When modifying code I find I often have to go through dozens of files to change the simplest of things. For example lets say I have a function pretty_print
and I change it to conform to camel case prettyPrint
. Now I want to go through the files apple1.js
to apple99.js
, and possibly a few orange.js
files in there. Is there a quick way to do this in Vim?
NOTE: this is not something I can automate, I actually need to go in and modify the code myself.
I know I can do :b <fileName>
, but, although it supports name completion/pattern matching, I don't think the pattern is carried over.
For example, if I do
:b apple*.js
and I hit tab, I'll get
:b apple1.js
but if I revisit that function (either by pressing :
+ upArrow or q:
) then if I hit tab it won't go to
:b apple2.js
What I want is to specify something like
:b apple*.js
edit the file, then when I type :w
, it moves to the next buffer. I would prefer to stay in Vim, I don't want to come out, type vim apple*.js
, go back into Vim and then use the :x
command. I realize this works, but I still need all the other files in case I want to, for example jump between tags.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这种情况下,最适合您的解决方案可能是使用
Vim 中集成了 grep 功能。以下命令执行搜索
对于与通配符
apple*.js
匹配的文件中的模式\
, 并将模式出现的位置存储在快速修复列表中 允许轻松跳过所有比赛。有关搜索的快速修复列表的更详细介绍
在文件中,请参阅 我对问题“加载获得的一组文件
通过 cmd-exec 进入 Vim 缓冲区”。
如果您只想打开与特定特定文件匹配的文件列表
通配符,将该文件的名称加载到参数列表中
,然后像往常一样使用
:n
和:N
在它们之间导航。Probably the most suitable solution for you in this case would be to use the
grep capabilities integrated in Vim. The following command performs a search
for the pattern
\<pretty_print\>
in files matching the wildcardapple*.js
,and stores locations of the pattern's occurrences in the quickfix list
allowing to easily jump through all the matches.
For more detailed introduction into the quickfix list with regard to searching
in files, see my answer to the question "Loading a set of files obtained
via cmd-exec into Vim buffers".
If you would like to simply open a list of files matching a particular
wildcard, load that files' names into the argument list
and then navigate between them using
:n
and:N
, as usual.从这里开始:
您最好对文件进行版本控制,并在更改后进行比较。
start with this:
You better version your files and do a diff after such a change.
Wikia 中的 BufSel 函数是否符合您的需求?
Does the BufSel function from Wikia matches your needs?