vimtricks.wiki Concise Vim tricks, one at a time.

How do I switch to the next buffer in Vim?

Answer

:bnext

Explanation

The :bnext (or :bn for short) command switches to the next buffer in Vim's buffer list. Buffers are Vim's way of keeping multiple files open simultaneously, and :bnext cycles through them in order.

How it works

  • :bnext moves to the next buffer in the buffer list
  • :bn is the shortest unambiguous abbreviation
  • If you are on the last buffer, it wraps around to the first one

Example

You have three files open:

  1 %a   "main.go"           line 42
  2      "utils.go"          line 1
  3      "config.go"         line 1

The % marker shows you are currently in main.go. Running :bnext switches to utils.go. Running :bnext again switches to config.go.

Tips

  • Use :bprev (or :bp) to switch to the previous buffer
  • Use :ls or :buffers to list all open buffers with their numbers
  • Use :b 3 or :b3 to jump directly to buffer number 3
  • Use :b filename to switch to a buffer by partial file name (with tab completion)
  • Use <C-^> (Ctrl+6) to toggle between the current and the alternate (last used) buffer — this is often faster than :bnext when flipping between two files
  • Use :bfirst and :blast to jump to the first or last buffer
  • Many users map :bnext and :bprev to more convenient keys:
nnoremap ]b :bnext<CR>
nnoremap [b :bprev<CR>

Next

How do I edit multiple lines at once using multiple cursors in Vim?