关闭待打开的 vim 窗口

发布于 2024-12-08 02:38:34 字数 244 浏览 0 评论 0原文

我知道我可以通过 :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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

数理化全能战士 2024-12-15 02:38:34

这听起来像是仓促学习 Vimscript 的工作!
特别是 :bufdoifmatch 语句!

尝试以下操作:

:bufdo if match(expand("%"), ".vim") >= 0 | bw | endif
  • bw 用于 Ex 模式中的缓冲区擦除: 运算符)
  • expand("%")< /code> 返回当前缓冲区的名称
  • match(string, pattern) 查找 patternstring 中的索引
  • |<如果您处于 Ex 模式,则 /code> 的单独行

这会匹配包含以下内容的缓冲区.vim 在它们的文件名中并关闭这些缓冲区。

我猜测如果这些是输入到 vimdiff 中的临时缓冲区,它们就不会以文件名开头。也许您可以使用 bufnr(".") 来输出当前缓冲区的编号。然后您可以关闭超过或之前特定数字的所有缓冲区。

您可能可以使用某些插件进行更多的缓冲区操作。我一直在考虑采用以下三个有助于管理插件的插件之一:

  • LustyExplorer
  • FuzzyFinder
  • minibufexpl
    我不能说出任何优点,但我在互联网和 IRC 上多次听到它们被提及。

This sounds like a job for hastily learnt Vimscript!
Particularly, the :bufdo, if, and match statements!

Try out the following:

:bufdo if match(expand("%"), ".vim") >= 0 | bw | endif
  • bw is for buffer wipe in Ex-mode (the : operator)
  • expand("%") returns the name of the current buffer
  • match(string, pattern) finds the index of a pattern in string
  • |'s separate lines if you're in Ex-mode

This 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 use bufnr(".") 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:

  • LustyExplorer
  • FuzzyFinder
  • minibufexpl
    I can't speak for any merits, but I've heard them mentioned several times over the internet and on IRC.
情话难免假 2024-12-15 02:38:34

我假设你用许多参数(称为......参数列表)打开 vim。

您可能应该重置它:

 :args %

您还可以有选择地管理列表(:argdelete)。更多信息::he arglist

I'm assuming you open vim with a number of arguments (known as... the argument list).

You should probably reset it:

 :args %

You can also selectively manage the list (:argdelete). More information: :he arglist

美人骨 2024-12-15 02:38:34

免责声明:我没有使用过 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.

诗笺 2024-12-15 02:38:34

这是一个糟糕的黑客,但将其放在这里,因为没有其他答案对我有用。

在 .vimrc 顶部添加不带 qoutes 的“qall”。

:e ~/.vimrc
:source ~/.vimrc
:q

所有文件打开后都会自动关闭。

然后在 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 .

:e ~/.vimrc
:source ~/.vimrc
:q

All files will close automatically after opening.

Then open vimrc in emacs or sed and remove qall.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文