When I'm editing (La)TeX files, Vim (with the default colorscheme) uses a bold font for the contents of \textbf{}, inverts the background color of \textit{}'s contents, etc.

I would like it to also underline the contents of \underline{}.

I've come up with a rather hacky solution that works in most cases, but breaks when the \underline{} contains a closing brace }:

highlight underline term=underline cterm=underline gui=underline
match underline /\\underline{\zs.\{-}\ze}/

(The underline highlight definition is necessary because Underlined changes the color of the text.)

How can I do this more elegantly?
I've looked at /usr/share/vim/vim74/syntax/tex.vim, but I can't seem to adapt something like syn region texBoldStyle matchgroup=texTypeStyle start="\\textbf\s*{" end="}" concealends contains=@texBoldGroup to my needs…

没有正确的解决方案

其他提示

Place the cursor over \underline{foo} and type that command:

:echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')

It will tell you which highlight group is used for that symbol. Once you have that information, you can try to add your highlight line to:

~/.vim/after/ftplugin/tex.vim

If the only problem is \} inside the \underline{}, then here's an improved regex:

/\\underline{\zs\(.\([^\\]}\)\@<!\)\+\ze}/

Alternatively, it is indeed possible to properly add it to syntax/tex.vim: add a syn cluster texUnderlineGroup (and add it under contains= for all appropriate existing clusters), add a syn region texUnderlineStyle, and finally add a hi texUnderlineStyle.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top