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/[qfor quickfix,]l/[lfor location list - Install
vim-unimpairedfor a complete set of bracket mappings - Use
:set hiddento allow switching with unsaved changes - Add
]t/[tfor tab navigation::tabnext/:tabprev