How do I filter the output of an Ex command to show only matching lines?
Answer
:filter /pattern/ command
Explanation
The :filter command restricts the output of another Ex command to only lines matching a given pattern. It works like piping through grep but entirely within Vim, and it applies to any command that produces multi-line output.
How it works
:filter /pattern/ {cmd}— show only output lines matchingpattern:filter! /pattern/ {cmd}— invert the filter, showing lines that do NOT match- The pattern uses Vim's regular expression syntax
{cmd}can be any Ex command that produces output::ls,:marks,:map,:highlight,:set, etc.
Example
To see only modified buffers:
:filter /+/ ls
To list only mappings that involve <Leader>:
:filter /Leader/ map
To show all highlight groups containing "Comment":
:filter /Comment/ highlight
To see all settings related to "tab":
:filter /tab/ set all
Tips
- Use
:filter!(with bang) to exclude matching lines instead — the inverse filter - Especially powerful with
:ls,:marks,:registers,:map, and:autocmdwhich produce verbose output - Combine with
:verbosefor even more detail::filter /pattern/ verbose map - Available in Vim 8.0+ and all Neovim versions