Showing Multiple View Panes at the Same Time in Vim
In this guide you'll learn how to split your view panes horizontally and vertically so that you can view multiple files at the same time in Vim.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

This is gonna be a really fun guide, I'm not sure if you've ever seen a Vim screencast or a screencast where the developer was using Vim in it, and you saw them having multiple code panes up at the same time or multiple windows open at the same time, all using Vim. And that's something that I use daily, it really helps from an efficiency point of view, and we're gonna go through a few different ways that we can do this, so this section's really gonna be dedicated to how you can work with multiple files in Vim.

I'm gonna start off, if you see where my position is at, I'm in the Rails application that we created, so I'm going to open up the Gemfile. And right here I have the Gemfile open, now if I want to open up on the side, another kind of file, I can start, make sure you're in command mode, and type vsp, which stands for vertical split pane, and here I can go and let's say I can open up my application controller. And as you can see, I have my application controller right here and this is the active pane.

large

And if I wanted to have a horizontal view here, and so let's say that I wanna have my seeds file, I can run another command and this time instead of vsp for vertical, now it's just sp for split pane, and I can do db/seeds, and now my seed file's right here, remember that in an earlier episode we edited it and cleared everything out, so nothing's inside of this file. But if you're wondering exactly which file you're in, if you look on the very bottom left-hand side, you can see that we're in db/seeds.

large

So now that you have these open, how can you switch to 'em? Obviously, because this is Vim, you're not gonna use your mouse, if you come and click over here nothing's gonna happen besides items being selected, but you're not actually able to access it. So, the way that you have access to change this, you have a few different options. I like to use control and then w twice, and so let me, I'll show you exactly, all of this is in your cheat sheet, obviously, but I'll type it out right here, just cause I think that's easier.

So if I type in control plus ww, this is going to allow me to switch from pane to pane, and it's just gonna go in order, so control ww takes me here to the application controller, I do it again and it takes me to the Gemfile, do it again and it cycles me all the way through.

large

To be 100% honest, this is what I use all the time, there are more options, and I'm gonna go through them with you, however I really like just the efficiency of only having to memorize as few things as possible, and it's pretty rare that I'll have more than three windows open, so hitting ww is not really a big issue. Now also I could close out all of those panes by pressing the o right afterwards, but let's open each one of those up.

Okay, so I'm gonna close that one out, and let's open up the Gemfile again. And let's open up the, let's see we had the, I forget which file, the application controller, that's right. There we go, okay, so now we're back and we're rearranged, and just so you remember that, I pressed the o in order to do that right after pressing that w, and that's if you wanna close it out.

But now let's say that I want to open up, or if I wanna navigate just to a different file, so I can do control ww like I did, but let's say that I wanna switch from side to side, the way that I would do that is by typing control, then w, and then I believe it is h, so control wh, yes, that switches me from right to left, and if you're wondering on how that works, or how you can have another thing to memorize, remember your home positions, remember h, j, k, and l, so if you think of this, your command is always gonna be control w, and then you can do h, j, k, and l, the same way that you would navigate normally.

So if I hit control wl, that's gonna take me to the right, the same exact way that if I was navigating through text, so it's gonna be control plus w, plus one of these positions, so h, j, and k or l and these are your main buttons. Like I said, I usually just do this first option with control ww, just so it cycles me through quickly, just cause I don't like the time to change to another key.

So I could very easily if I was, say, in this Gemfile right here, and I wanna switch up, I could do control w and then h, and that's gonna take me right up there, and this is a very cool way of being able to navigate, have multiple file panes open all at the same time. Whenever I'm developing, my developer interface usually looks something like this, I'll either have two or three panes open at any given time, it just makes for a very efficient kind of development environment.

Now if you want to close one of these out, you can close it out just like it's a pane all by itself, so just like it existed by itself, say I wanna close this controller out, I can just type the command nq, and that closes it out, and then I can do the same thing here, and here I'm gonna do q, I'm not gonna save it, and quit, so I am back and I was able to navigate through each one of those and then also be able to close all of them out.

Now that works, and that's a standard way of doing it, in the next guide I'm gonna show you how we can customize the size of the panes, so I'll see you then.