How do I switch to a buffer by typing only part of its filename?
Answer
:b {partial}
Explanation
The :b command accepts a partial filename and switches to the first buffer whose name contains that string. This makes navigating between open buffers fast — you rarely need to type a full path or remember a buffer number.
How it works
:btakes either a buffer number or a name (or partial name)- Vim matches the partial string against all open buffer names (full paths included)
- Tab-completion lists all matching buffers if multiple match the partial string
- If the match is ambiguous, Vim will show an error and list candidates — narrow it down by adding more characters
Example
You have these buffers open:
1 /home/user/project/main.go
2 /home/user/project/handlers/user.go
3 /home/user/project/handlers/auth.go
Typing :b auth switches immediately to auth.go. Typing :b user would be ambiguous (matches both user.go and the /user/ path in buffer 1), so Vim prompts with matches. Typing :b handlers/u narrows it to user.go.
Tips
- Press
<Tab>after:bto cycle through matching buffers — the completion is immediate - Combine with
:sb {partial}to open the matched buffer in a horizontal split - Use
:vb {partial}(or:vertical sb {partial}) to open it in a vertical split :b#(or<C-^>) switches to the alternate buffer — the most recently visited one