How do I show only buffers matching a pattern in Vim's :ls output?
Answer
:filter /pattern/ ls
Explanation
When you have many open buffers, plain :ls output gets noisy fast. :filter lets you run any Ex command and keep only lines that match a pattern, so you can narrow buffer listings without changing your buffer state. This is a high-signal way to find a target buffer by filename fragment, extension, or directory segment.
How it works
:filter /pattern/ ls
:filter /pattern/applies a regex filter to the command outputlsprints the current buffer list
Only matching lines are displayed. This is output filtering, not buffer deletion, so it is safe to run repeatedly while you refine the pattern.
Example
Suppose :ls contains many entries, including:
3 %a "src/main.go"
9 "src/db/migrate.go"
17 "README.md"
Running:
:filter /\.go$/ ls
shows only Go buffers:
3 %a "src/main.go"
9 "src/db/migrate.go"
Tips
- Pair with
:b {nr}once you find the buffer number you want. - Use case-insensitive regex atoms (
\c) inside the pattern when needed.