Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off highlighting a certain pattern in vim

In vim, I am editing a file of filetype "markdown", but which contains latex math expressions such as $x_i$. Vim's syntax highlighting for markdown thinks the pattern *_* (letter-underscore-letter) is an error, and highlights the underscore in such patterns bright red. I would like to turn this off by adding a line to my .vimrc:

autocmd BufEnter *.Rmd "Dear vim, please don't highlight the pattern *_*"

What is the appropriate command to do that? Is it possible at all to do that in .vimrc, without editing a syntax file?

Note: I want to keep the markdown syntax highlighting in general, only turn off that particular feature.

like image 817
sieste Avatar asked Oct 02 '13 13:10

sieste


2 Answers

You have to modify the Markdown syntax for that. One way would be to remove the parsing of the error:

:syn clear markdownError

But that would cause the other syntax rules to start an italic section on that _ char. Better just clear the error highlighting with:

:hi link markdownError Normal

To maintain the general error highlighting, but only define exceptions for the special $x_i$ string, define an overriding syntax group; luckily, this is easy because no existing syntax is there:

:syn match markdownIgnore "\$x_i\$"

(Adapt the regular expression to match all possible math expressions.) This needs to be put into ~/.vim/after/syntax/markdown.vim to be executed after the original syntax script.

like image 101
Ingo Karkat Avatar answered Oct 04 '22 06:10

Ingo Karkat


If you want to remove _ from the markdown error pattern, you can redefine it. In my case I want to turn off error notifications of underscores in a word as I put a lot of URLs in my documents.

There's a line that defines the error pattern inside syntax/markdown.vim file

" Original error pattern
syn match markdownError "\w\@<=_\w\@="

Remove the _ from the pattern and add that to ~/.vim/after/syntax/markdown.vim.

" New error pattern without the underscore
syn match markdownError "\w\@<=\w\@="
like image 44
Sanghyun Lee Avatar answered Oct 04 '22 06:10

Sanghyun Lee