开发者

closing pending vim windows to open

开发者 https://www.devze.com 2023-04-11 06:10 出处:网络
I know that I can close all opened buffers in vim by :qall. I开发者_StackOverflow中文版 want to close event to pending opening buffers.

I know that I can close all opened buffers in vim by :qall.

I开发者_StackOverflow中文版 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,


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.


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消