Step 3 of 6

11. Buffers

Moving between buffers

We’ve already seen how we can use the :bn and :bp commands to move sequentially through our buffer list. There are lots of other ways to get around, though!

One way is using the :buffer command, or :b for short. You might have noticed that the output of :ls has a number in the first column. This number is unique to the buffer, and never changes. If you give one of these buffer numbers to the :b command — like :b 1 — Vim will take you to that buffer.

Work through the checklist below. The three files from last step — a.txt, b.txt, and c.txt — are already waiting in your buffer list, so there’s nothing to open first. Check the numbers Vim assigned them with :ls (buffers you haven’t visited yet show line 0 — Vim loads them the moment you jump in), then use :b <number> to bounce straight to a buffer — no repeated :bn needed.

  1. Check the buffer numbers with :ls Each buffer's number is in the first column — type :ls, hit Enter, and hit Enter again once you've read the list.
  2. Jump to buffer 3 Buffer 3 is b.txt — type :b 3 and hit Enter.
  3. Jump back to buffer 1 exercise.txt was loaded first, so it's buffer 1 — type :b 1 and hit Enter.
Check the buffer numbers with :ls Each buffer's number is in the first column — type :ls, hit Enter, and hit Enter again once you've read the list.

Next: Jump to buffer 3

Loading editor…