Step 5 of 6

11. Buffers

Jumping back and forth

Most of the time when we’re working with multiple files, we’re jumping back and forth between just two files at any given time. For example, we might be switching between two source code files, or we might be switching between a LaTeX document and a bibliography. Vim has a tool that can help us here.

It’s called the “alternate file”. When you switch buffers, Vim keeps track of the buffer you were in last so that we can switch back to it quickly. The keymap for jumping to the alternate file is <C-^> — that’s hitting the 6 key on your keyboard while holding control.

Work through the checklist below. foo.txt is already in your buffer list, so jump straight to it with :b — that switch makes this file the alternate. Then use <C-^> to flip between the two — no command line needed at all.

  1. Jump to foo.txt with :b Use the :b command however you like — :b foo, or :b f plus Tab — and hit Enter.
  2. Flip to the alternate file exercise.txt is your alternate file now — to flip back to it, hold Control and press 6.
  3. Flip back again foo.txt is the alternate now, waiting to take you straight back — hold Control and press 6 once more.
Jump to foo.txt with :b Use the :b command however you like — :b foo, or :b f plus Tab — and hit Enter.

Next: Flip to the alternate file

Loading editor…