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

How do I set up efficient keybindings for cycling through buffers?

Answer

:nnoremap ]b :bnext<CR>

Explanation

Mapping ]b and [b to :bnext and :bprev creates an intuitive bracket-style navigation for buffers, matching the convention used by unimpaired.vim. This turns buffer navigation into a fast, muscle-memory operation.

How it works

  • ]b — go to next buffer (:bnext)
  • [b — go to previous buffer (:bprev)
  • ]B — go to last buffer (:blast)
  • [B — go to first buffer (:bfirst)

Example

nnoremap ]b :bnext<CR>
nnoremap [b :bprev<CR>
nnoremap ]B :blast<CR>
nnoremap [B :bfirst<CR>
Buffers: main.py, utils.py, config.py
Current: utils.py
]b → config.py
]b → main.py (wraps around)
[b → config.py

Tips

  • This convention extends to other navigations: ]q/[q for quickfix, ]l/[l for location list
  • Install vim-unimpaired for a complete set of bracket mappings
  • Use :set hidden to allow switching with unsaved changes
  • Add ]t/[t for tab navigation: :tabnext/:tabprev

Next

How do I return to normal mode from absolutely any mode in Vim?