How do I switch to a buffer by typing part of its filename?
Answer
:b partial<Tab>
Explanation
The :b (buffer) command accepts partial filename matching with tab completion. You don't need to remember buffer numbers or type full paths — just type enough characters to uniquely identify the file.
How it works
:b main<Tab> " Completes to 'main.go' if unique
:b hand<Tab> " Completes to 'handlers.go'
:b test<Tab> " Cycles through buffers containing 'test'
Substring matching
Vim matches against any part of the filename:
:b util " Matches 'src/utils/helpers.go'
:b spec " Matches 'tests/handler_spec.rb'
With set hidden
Ensure you can switch buffers without saving first:
:set hidden " Allow switching from unsaved buffers
Multiple matches
If multiple buffers match, Tab cycles through them:
:b test<Tab> " → test_handler.go
:b test<Tab> " → test_utils.go
:b test<Tab> " → test_model.go
Or use :ls to see all buffers first:
:ls " List all buffers with numbers
:b 3 " Switch to buffer 3
Tips
- Enable
wildmenufor a visual completion bar::set wildmenu - Set
wildmode=longest:full,fullfor bash-like completion :sb partialopens the buffer in a new split:vert sb partialopens in a vertical split:b #switches to the alternate buffer (same as<C-^>)- With
wildmenuenabled, use<Left>/<Right>to browse matches - This is often faster than fuzzy finders for small projects