Step 7 of 8

Moving windows around

Moving windows around

You can rearrange windows to get your layout just right — and look, it’s hjkl again! Capitalised this time: Space-w H, Space-w J, Space-w K, and Space-w L swap the current window with its neighbour to the left, below, above, or to the right. Your cursor travels with the window, so after a swap you’re still editing the same buffer — it’s just somewhere else on the screen.

One more rearranging trick: Space-w t transposes the splits, turning a side-by-side pair into a stacked one (and back again). Handy when you opened a split in one direction and change your mind.

There are two files alongside the editor’s exercise.txt: a.txt and b.txt. Work through the checklist: open them in splits, then swap them around.

  1. Open a.txt in a horizontal split Type :hsplit a.txt and press Enter — a.txt opens in the lower window.
  2. Swap it with the window above using Space-w K Press Space, then w, then shift-Ka.txt is now on top, and your cursor goes with it.
  3. Open b.txt in a vertical split Type :vsplit b.txt and press Enter — b.txt opens to the right of a.txt.
  4. Swap it leftwards with Space-w H Press Space, then w, then shift-Hb.txt and a.txt trade places.
  5. Flip the layout with Space-w t Press Space, then w, then t — the side-by-side pair is now stacked.
Open a.txt in a horizontal split Type :hsplit a.txt and press Enter — a.txt opens in the lower window.

Next: Swap it with the window above using Space-w K

Loading editor…