Step 3 of 9

12. Windows

Two windows, one buffer

I mentioned that :split and :vsplit accept a filename — but the filename is actually optional! Run them bare and you’ll split the current window in two, leaving the new window peering into the same buffer.

Interesting! Multiple windows can be “looking at” the same buffer. This is really useful in a large file: you can keep two far-away sections visible on screen at the same time. And since it’s all one buffer, an edit made in any window shows up in all of them.

Work through the checklist: split the window a couple of times, then make an edit and watch it appear everywhere at once.

  1. Split the window with a bare :vsplit No filename this time — two windows will peer into the same buffer. Type :vsplit and hit Enter.
  2. Split again with a bare :split That makes three windows, all showing this one buffer — type :split and hit Enter.
  3. Delete the top line and watch every window change Press gg to jump to the first line, then dd to delete it — the edit appears in _all_ the windows at once.
Split the window with a bare :vsplit No filename this time — two windows will peer into the same buffer. Type :vsplit and hit Enter.

Next: Split again with a bare :split

Loading editor…