Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 609
Derek Thurn Avatar asked Oct 11 '11 19:10

Derek Thurn


People also ask

How do you highlight text in vim?

If you want to select the entire line in a file, press V. Now when you press k or j to go up and down, vim will select the entire line above and below your cursor. Finally, you can select text in columns by pressing ctrl+v and moving up or down the block.

Does vim support syntax highlighting?

One of useful features of vim is syntax highlighting. The readability of any source code or configuration file can be increased by using different front and color for different part of the file. This task can be done by using syntax highlighting feature of vim.

What vim command turns on syntax highlighting?

If you already have opened a file in Vim, below are the steps to turn on syntax highlighting: Press the Escape (Esc) key to enter Normal mode in Vim. Type the colon : symbol to indicate that you're typing a command. After the colon, type syntax on .


2 Answers

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

like image 95
Habi Avatar answered Nov 11 '22 10:11

Habi


You could make your own syntaxfile with an according colortheme, using "bold", "italics" and the like. It wouldn't hide anything, so that your syntax must work with the original text. For example this could be your syntax for headers

In your syntax you would need:

syn match Header '^\s*\u*\.\s.*$'  contains=ALL
hi link Header   ModeMsg

and in the colortheme

hi ModeMsg gui=bold guifg=NONE guibg=NONE cterm=bold ctermfg=NONE ctermbg=NONE term=bold

then a header like this

1. This is my new header, being bold

would be shown bold, without any markup at all. By the way, you can export it with the TOhtml feature while keeping the highlighting.

like image 42
inknoir Avatar answered Nov 11 '22 09:11

inknoir