关闭待打开的 vim 窗口
我知道我可以通过 :qall 关闭 vim 中所有打开的缓冲区。
我想关闭待打开缓冲区的事件。
我在查看 P4 沙盒中的更改时遇到问题。当我在多个文件中进行更改时,我尝试使用“P4 diff”检查我的代码并将我的 P4DIFF 设置为 vimdiff。
它会一一打开所有已更改文件的 vimdiff。现在,如果我有 10 个打开的文件,在查看 2 个文件后,我想关闭剩余 8 个文件的 diff。我怎样才能做到这一点?
谢谢,
I know that I can close all opened buffers in vim by :qall.
I want to close event to pending opening buffers.
I have problem while reviewing my changes in P4 sandbox. When I have changes in multiple files and I try to review my code with "P4 diff" and set my P4DIFF to vimdiff.
It opens one by one vimdiff of all changed files. Now if I have 10 opened files and after reviewing 2 files I want to close diff for remaining 8 files. How can I do that?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这听起来像是
仓促学习 Vimscript 的工作!特别是
:bufdo
、if
和match
语句!尝试以下操作:
bw
用于 Ex 模式中的缓冲区擦除
(:
运算符)expand("%")< /code> 返回当前缓冲区的名称
match(string, pattern)
查找pattern
在string
中的索引|<如果您处于 Ex 模式,则 /code> 的单独行
这会匹配包含以下内容的缓冲区
.vim
在它们的文件名中并关闭这些缓冲区。我猜测如果这些是输入到 vimdiff 中的临时缓冲区,它们就不会以文件名开头。也许您可以使用
bufnr(".")
来输出当前缓冲区的编号。然后您可以关闭超过或之前特定数字的所有缓冲区。您可能可以使用某些插件进行更多的缓冲区操作。我一直在考虑采用以下三个有助于管理插件的插件之一:
我不能说出任何优点,但我在互联网和 IRC 上多次听到它们被提及。
This sounds like a job for
hastilylearnt Vimscript!Particularly, the
:bufdo
,if
, andmatch
statements!Try out the following:
bw
is forbuffer wipe
in Ex-mode (the:
operator)expand("%")
returns the name of the current buffermatch(string, pattern)
finds the index of apattern
instring
|
's separate lines if you're in Ex-modeThis matches buffers that contain
.vim
in their filenames and closes those buffers.I'm guessing if these are temp buffers that are fed into
vimdiff
, they wouldn't have file names to begin with. Maybe you can usebufnr(".")
to output the number of the current buffer. Then you can close all buffers past or before a certain number.You can probably do even more buffer manipulation with certain plugins. I've been considering adopting one of the following three plugins that help manage plugins:
I can't speak for any merits, but I've heard them mentioned several times over the internet and on IRC.
我假设你用许多参数(称为......参数列表)打开 vim。
您可能应该重置它:
您还可以有选择地管理列表(
:argdelete
)。更多信息::he arglist
I'm assuming you open vim with a number of arguments (known as... the argument list).
You should probably reset it:
You can also selectively manage the list (
:argdelete
). More information::he arglist
免责声明:我没有使用过 perforce,所以我不得不做出一个假设:当多个文件有未提交的更改时,它会像很多 VCS 一样运行并运行配置的 diff 命令(在本例中为 vimdiff)依次在每个更改的文件上(我想这就是您所说的“打开所有更改文件的一一vimdiff”的意思)。
如果是这种情况,那么在查看任何特定文件的更改时,vim 将不会对任何剩余文件有任何引用,因此单个 vim 会话中的任何欺骗都不会帮助您。
如果你愿意改变你的工作流程,你也许可以用我发现的这个 vim 脚本做一些事情: http://www.vim.org/scripts/script.php?script_id=240
它声称是根据 P4 GUI 建模的,因此希望能够完全适合您的使用。从脚本的概述来看,听起来它应该能够向您显示哪些文件已更改的摘要,并允许您查看更改。
如果这些都不适合您,您可以在关闭文件的 vimdiff 会话后立即尝试旧的最喜欢的
Ctrl-C
。DISCLAIMER: I've not used perforce, so I've had to make an assumption: that when multiple files have uncommitted changes, it will behave like a lot of VCS's and run the configured diff command (in this case, vimdiff) on each changed file in turn (I'm thinking this is what you meant by "opens one by one vimdiff of all changed files").
If this is the case, then vim won't have any references to any of the remaining files when viewing the changes for any particular file, so no amount of trickery within a single vim session is going to help you.
If you are willing to change your workflow at all, you may be able to do something with this vim script I found: http://www.vim.org/scripts/script.php?script_id=240
It claims to be modelled after the P4 GUI, so hopefully could fit neatly into your usage. From the overview of the script, it sounds like it should be able to show you a summary of which files have changed and allow you to view the changes.
If none of this is suitable for you, you could always try the old favourite
Ctrl-C
immediately after closing a vimdiff session for a file.这是一个糟糕的黑客,但将其放在这里,因为没有其他答案对我有用。
在 .vimrc 顶部添加不带 qoutes 的“qall”。
所有文件打开后都会自动关闭。
然后在 emacs 或 sed 中打开 vimrc 并删除 qall。
This is a bad hack but putting it here as no other answers worked for me.
Add "qall" without qoutes on top of your .vimrc .
All files will close automatically after opening.
Then open vimrc in emacs or sed and remove qall.