Domanda

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.

È stato utile?

Soluzione

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.

Altri suggerimenti

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\@="
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top