How do I visually hide or conceal matched text in Vim?
Answer
:syntax match Conceal /pattern/ conceal
Explanation
Vim's conceal feature lets you visually hide text that matches a pattern, or replace it with a single character. This is powerful for reducing visual clutter — hiding markup syntax, long namespaces, or boilerplate while keeping the actual text intact.
How it works
:syntax match Conceal /pattern/ conceal— hides matching textconceal cchar=X— replaces concealed text with character X instead of hiding itconceallevelcontrols the behavior (0=off, 1=replace with cchar, 2=hide completely, 3=hide even cchar)concealcursorcontrols concealing on the cursor line
Example
:set conceallevel=2
:syntax match Conceal /https:\/\/[^ ]\+/ conceal cchar=🔗
Before: Visit https://example.com/very/long/url for details
After: Visit 🔗 for details (the URL is still there, just hidden)
Tips
- Set
concealcursor=nvicto keep text concealed even when cursor is on the line - Use
conceallevel=1withccharfor readable replacements - Conceal is used by plugins like
vim-markdownto hide markup syntax - The actual text is preserved — concealing is purely visual