Better Programming

Advice for programmers.

Follow publication

Splitting Windows on Vim

Photo by Max van den Oetelaar on Unsplash

Screens are big these days, so it makes sense to split them to see multiple files at the same time, or different parts of the same file at the same time.

Most editors can be split into different regions. On Vim, these regions are called “windows.”

Splitting Windows

To open a new window, you can use the :split command (or CTRL-W s), which splits the screen horizontally into two windows showing the same file. To split them vertically use :vsplit or CTRL-W v.

CTRL-W w can be used to jump between all the open windows. It wraps around.

You’ll notice that all the Window commands on Vim have the form CTRL-W {char}, in which you must press CTRL-W first and then another character. (CTRL-W CTRL-{char} does the same thing, in case you let go of the CTRL key a bit later.)

To close a window, use the :close command (or CTRL-W c).

The :only command (or CTRL-W o) closes all windows except for the current one.

Tabs and Windows

Happy editors are all alike; every unhappy editor is unhappy in its own way.

It must be observed that every single modern editor known to mankind — including but not limited to Sublime Text, Atom, VSCode, and JetBrains editors — let you split the screen into multiple panes and then have tabs inside each pane.

But Vim does the opposite — It has tabs that contain split panes (aka windows):

To be fair, this is just a design difference. There’s no one correct way to design the layout of an editor. Both ways have advantages and disadvantages.

Vim only visually doesn’t have tabs in each pane (window) — you can still switch what file (buffer) each window is displaying.

You actually have more freedom in Vim because a file doesn’t belong to some pane, they’re completely independent. Any window can display any buffer.

Therefore, here’s a fairer way to show the different methodologies:

So, the Vim tab system is not really a different or opposite way of doing it, it’s an additive feature on top of the usual panes and files workflow, because you can have different tabs with different layouts (arrangements of windows) for different contexts.

But if you don’t engage with the tabs feature at all you can still have basically the same workflow as other editors by just using windows and whatever your preferred way of switching and creating buffers is (using Command-line mode or plugins like telescope, bufferlines, nvim-tree or similar, etc).

Vim’s Final Form

In fact, we can display all of this information in one final graph.

Brace yourselves, because this is the truest form of Vim.

Mere mortals rarely survive after looking at it.

Here we go:

Closing thoughts

If you made it this far, you are the chosen one to bring balance to the Vimosphere. Go forth and use your newfound knowledge to bring peace to this land. Resist the temptation of VSCode and all other dark forces.

Microsoft and all the dark lords of the software engineering universe will tremble at the sound of your name if you manage to avoid their telemetry of despair, which empowers their soulless machines of doom.

Good luck. May the Vimscript be with you.

Seriously though, you can check all my other Vim tips here:

Thanks for reading! If you enjoy humorous tech stories like these and want to support me to keep writing forever, consider signing up to become a Medium member. It’s $5 a month, giving you unlimited access to stories on Medium. If you sign up using my link, I’ll earn a small commission. You can also follow me on Medium and Twitter.

Sebastian Carlos
Sebastian Carlos

Written by Sebastian Carlos

Middle-end developer. Programming, satire, and things. You can buy me a coffee at https://ko-fi.com/sebastiancarlos

No responses yet

Write a response