Lesson 13 of 26

Multiple Windows

Duration: 3:07 Watch on YouTube (external link, opens in new tab)

Markdown version

In this lesson

Roy opens a second file next to the current one with vsplit (split adds a horizontal window instead) and moves between windows with Ctrl-W followed by h, j, k or l. He closes a window with q or keeps only the current one with only. On a Mac he recommends turning Caps Lock into Control under the keyboard settings' modifier keys, so that Control is easier to reach.

Transcript

446 words

[00:07] (external link, opens in new tab) At this point, we've only been working with a single file each time. So, I want to show you how to work with more than one file at the same time or having more than file one file open and visually visible at the same time. And there are many concepts in Vim such as buffers and windows. I'm going to show how to have multiple windows in Vim. And the command to do this is to either use split or vsplit. So split will have a horizontal window and vsplit will add a vertical window.

[00:38] (external link, opens in new tab) So let's say I want to edit my vimrc on the side here. I'm going to type command here at the bottom vsplit and the name of the file. So home vimrc. And now I have two files. Now the question is how do I move from one file to another? The answer is that you use control W to say window and then you move right or left.

[01:09] (external link, opens in new tab) So you can move right or left either with H or L or J and K if the window is below or above you. So here I'm going to do if I want to move right I'll say control W and then L to move right. WH to move left. And usually it just a very quick syntax. I'm going to try to type it actually very strongly so you can hear how fast it goes

[01:47] (external link, opens in new tab) Now let's say you want to close. You either type Q on the current file like this and you're left with just one of them. Or if I just repeat this, you can type only to remain the only file open. So I'm going to move to the file I want to have open. So now I am in the in this file. I'm going to type command sorry command only.

[02:17] (external link, opens in new tab) This remains the only window. So that way you don't have to close multiple windows if you have more than two open. So those are really really basic steps in working with multiple windows. Now if you're in a Mac just like me and one of the things that is very highly recommended is to transform the caps lock into a control. So it's much easier to type control. And the way you do that is in the keyboard settings under keyboard you can click modifier keys

[02:48] (external link, opens in new tab) And then there either your internal or your external keyboard you change caps lock to also be control and that way it's actually much easier to reach with your left pinky to the control instead of going down. So, it's much easier on your hands that way.