61

Sometimes when I'm working on a file, I'll open up multiple files just to get an idea of the current flow of the code up to a point. However this sometimes leads to multiple files being open at a time by split. Is there a command to quit all except the selected window?

1

2 Answers 2

77

If you want to close all windows(splits) except the current one:

:only

If you want to close all tabs except the current one:

:tabonly

If you want to delete all hidden buffers (files open but not visible in any window on any tab), you'll have to add a function to your vimrc. Some people have posted possible functions to here and here

I'm not sure exactly which of these you were trying to accomplish, but hopefully some combination of these commands does the trick.

56

Press Ctrl+w,o to quickly close all split windows, but current one.

Alternatively use the command: :on (:only).

:on[ly][!] Make the current window the only one on the screen. All other windows are closed.

See also:

5
  • 2
    Ctrl+W,o <<< this should be accepted answer
    – Leo
    Commented Jun 16, 2016 at 14:26
  • It'd be cool if you could toggle splits, like zoom in Tmux. Anyone know if that's possible?
    – domi91c
    Commented Feb 19, 2017 at 7:52
  • 1
    @portOdin You need to ask another question then.
    – kenorb
    Commented Feb 19, 2017 at 11:53
  • Does "close" here mean closing the buffers (equivalent of :q) or just hiding them?
    – stillanoob
    Commented Jan 16, 2019 at 15:21
  • @stillanoob I think they're closed, as :tabs doesn't show them.
    – kenorb
    Commented Jan 16, 2019 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.