Close all other splits
We’ve written many posts about splits and for good reason: They are a powerful tool in the arsenal of every Vim user with screen real estate.
One of the consequences of working with splits is they can accumulate. When you get in the flow, it’s easy to open too many splits as a part of navigating among files in a project. After opening one too many splits, I often want to refocus my attention on only one of those files. The way to do this in Vim is with the
:only command, which will close all the other splits except the active one.
But there’s an even more convenient shortcut:
<ctrl-w> o will execute the
:only command and it’s just a single key combo:
<ctrl-w> o– Close all other splits except the active one
:only– Same, but more tying
There’s a quick demo of this in action at the bottom of the post.
A very common usecase of this feature is when I wrap up a bunch of work and I open the Fugitive
:Git status window. I generally want this to be the only window open while I stage changes and prepare a commit. Since I might have 3 or more files splayed out on the operating table, I tap
<ctrl-w> o and prepare my commit. If you work a lot in Git, consider our email course Git Better with Vim, which features 24 lessons about using Git without leaving Vim.
We’ve seen great feedback on the tips offered in the course, like this Tweet from @tekkie:
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?