vimtricks.wiki Concise Vim tricks, one at a time.

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 text
  • conceal cchar=X — replaces concealed text with character X instead of hiding it
  • conceallevel controls the behavior (0=off, 1=replace with cchar, 2=hide completely, 3=hide even cchar)
  • concealcursor controls 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=nvic to keep text concealed even when cursor is on the line
  • Use conceallevel=1 with cchar for readable replacements
  • Conceal is used by plugins like vim-markdown to hide markup syntax
  • The actual text is preserved — concealing is purely visual

Next

How do I return to normal mode from absolutely any mode in Vim?