Search code examples
vimvim-syntax-highlighting

Vim syntax highlighting hide characters


I'd like to implement a syntax file for vim that hides certain characters in the file. Specifically, I want to write an improved highlighter for reading Markdown files that doesn't display some of the formatting characters, preferring instead to indicate them implicitly. For example, I'd like to have things like *bold* render as simply bold with bold text, or to have headings like

My Header
=========

not show their underline, but just appear a different color. I haven't managed to find any examples so far of vim syntax files that hide specific characters from display. Is this something that is possible in vim? If so, how?


Solution

  • To hide syntax items - or just certain characters - the conceal or Ignore arguments can be used. See

    :help hl-Ignore
    :help syn-conceal
    

    For an example see the syntax file "help.vim" which is part of crefvim. CRefVim is a C-reference manual which is embedded in the Vim help system. The "help.vim" syntax file extends the standard syntax highlighting for help files.

    An example. The '$' character is used here to show text in italic:

    example on how to use Ignore syntax argument, help.vim

    Maybe this example is a good starting point for you to dig further...

    Habi