0

I am currently using default syntax highlighting for LaTeX in vim on a Windows machine. Here are the contents of my _vimrc file:

set number
set belloff=all
syntax on
set backspace=indent,eol,start
set expandtab
set tabstop=4
set shiftwidth=4
set autoindent
set ruler

Unfortunately, I don't really like the syntax highlighting for the underscore character _, and I would like to override this without overriding the general LaTeX defaults built into Vim.

How can I do this?

3
  • 2
    I believe you're referring to the syntax highlighting used for errors. By default, it is shown as a small red block. This shows you there is a syntactical errors (you need to escape underscores as \_) Is this correct? If you're referring to something different, it would be helpful to see an image in your question.
    – r_31415
    Jun 15 at 1:11
  • Yes that's what im referring to
    – user32882
    Jun 15 at 5:07
  • 1
    I posted an answer with more information about overriding this particular syntax group.
    – r_31415
    Jun 15 at 6:10

1 Answer 1

1

Since you're referring to the red block shown in underscores without escaping (\_) or outside math context, then you need to figure out what is the syntax group used in that case.

From this answer, this is the code snippet to show you that information:

:let s = synID(line('.'), col('.'), 1) | echo synIDattr(s, 'name') . ' -> ' . synIDattr(synIDtrans(s), 'name')

Alternatively, if there are very few similar styles, you could scroll down the list after running :syn list.

In any case, the culprit seems to be the syntax group called texOnlyMath. Therefore, you can change it with a new file in ~/.vim/after/syntax/tex.vim with the following line:

hi texOnlyMath ctermbg=Blue ctermfg=Black

Obviously, this is just an example. You can change cterm or gui colors according to your needs (see :h cterm-colors, :h gui-colors)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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