A search pattern used with /, entered on the vim command line, can be very complex.

But even for a normal regular expression pattern, syntax highlight of the expression syntax would be helpful.

The pattern syntax in vim provides a large number of special pattern atoms. Some of them use multiple characters.
I do need to look them up to use them - that's easy.
The harder part is to continue editing the pattern, because it can become hard to read quickly.

I think even a very simple kind of syntax highlight for the pattern input would be helpful, like three colors for text, standard pattern atoms and special pattern atoms.

It would help users new to writing nontrivial patterns a lot - and also, it would help experienced users, new to writing even more advanced patterns, just the same way.

  • I am not sure what your question is here. Do you want general highlight of the search string? Or highlighting as you type? Do you want to change the color of the highlighting based on the type of search string?
    – Bernhard
    Feb 28, 2015 at 10:30
  • Some basic highlighting is available in the search window (invoked by q/). It's not extensive, but perhaps a syntax plugin could improve it.
    – tommcdo
    Feb 28, 2015 at 12:04
  • I guess I was thinking about the command window (q:). It uses VimScript highlighting.
    – tommcdo
    Feb 28, 2015 at 12:11
  • @Bernhard Yes, it should be highlighting as you type, ideally. Thanks to point it out. Basically, I want to make the syntax of the pattern after / visible. Literal text should be a fixed color (a code fragment in the pattern is not highlighted). Feb 28, 2015 at 15:28

2 Answers 2


There's no highlighting in the command-line; that's not implemented.

What you can do is open the command-line window via q/, and :set syntax=... there (also automatically via :autocmd CmdwinEnter / setlocal syntax=...). Unfortunately, even the syntax for Vimscript doesn't provide any differentiation in /.../ patterns. So, you'd have to write such syntax (e.g. named vimregexp) yourself. A worthwhile challenge, and such plugin would probably be well received by the Vim community (and could even be included in / be an extension of the syntax/vim.vim plugin).


You can quickly check if your regexp search pattern works by using IncSearch.vim plugin. It incrementally highlights ALL pattern matches as you type it.

  • 2
    It might be useful, but I think this post is more suited to a comment, since it doesn't even come close to answering the question.
    – muru
    Mar 4, 2015 at 22:03
  • @muru Somehow it's approaching the same problem from a different side: We can not visualize the structure of the pattern in real time; Ok, but instead we visualize what the pattern does in real time. I take it as at least related enough to be an answer - and it may turn out to be pretty useful. Mar 4, 2015 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.