Vim: Underline content of \underline{} in (La)TeX files - vim

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.

Related

Correct (and stable) vim syntax highligthing with multi-line matches

I'm trying to create a vim syntax file that has a multi-line match but this causes incorrect syntax highlighting if vim redraws the buffer when the current line comes after the multi-line match.
For instance, I'd like vim to apply the following colors using this criteria (and in this order):
Color A: Any set of two adjacent lines if the first is composed of
one or more '=' characters
Color B: If the line starts with '-'
Color C: All other lines
I have tried using the following vim syntax commands for vim:
syn clear
syn sync linebreaks=2
syn sync minlines=10
syn sync maxlines=1000
syn match colora '^=\+\n.*' display
syn match colorb '^-.*' display
syn match colorc '^[^=-].*' display
highlight colora ctermfg=DarkRed cterm=bold
highlight colorb ctermfg=DarkGreen cterm=bold
highlight colorc ctermfg=DarkCyan
But as I mentioned and can be seen from the screenshots, when editing the file, sometimes the second line of the multi-line match switches from color A to color C. This probably can be fixed with the sync options but I'd like to avoid syncing from the beginning of the file for performance reasons.
Screenshots:
The colorc can match in the second line of a colora match; that ambiguity causes the problem.
There should be no need to define a highlight group for "all other text"; that's what the Normal highlight group is for. Trying to work against that is just asking for trouble.
This (fallback highlighting) could be a valid use case for a region of text, though. In that case, define colorc as a :syntax region (that fully encompasses all lines covered by colora and any other multi-line match), and add contains=colorb,colorc. With that, the matching is unambiguous, and you should see correct highlighting at all times, without meddling with the :syntax sync settings.

How to change the coloring scheme of Gdiff in vim-fugitive plugin?

I use the vim-fugitive plugin to check git diff. The coloring scheme to highlight the code changes does not compliment my solarized background. I am not able to see the commands to change the coloring scheme of Gdif. Could anyone help me changing the coloring scheme?
From :help :diffupdate:
|hl-DiffAdd| DiffAdd Added (inserted) lines. These lines exist in
this buffer but not in another.
|hl-DiffChange| DiffChange Changed lines.
|hl-DiffText| DiffText Changed text inside a Changed line. Vim
finds the first character that is different,
and the last character that is different
(searching from the end of the line). The
text in between is highlighted. This means
that parts in the middle that are still the
same are highlighted anyway. Only "iwhite" of
'diffopt' is used here.
|hl-DiffDelete| DiffDelete Deleted lines. Also called filler lines,
because they don't really exist in this
buffer.
So, for example, something like
:highlight DiffAdd ctermfg=253 ctermbg=237 guifg=#dadada guibg=#3a3a3a
in your colorscheme should change the colour of the added lines.

Changing color of vim syntastic error window

I have installed syntastic on VIM to help me show errors in PHP code however with the current colorscheme/setting I have to following colors:
As you can see it's very hard to read, I wonder if there is a way to change the color if this error window specifically.
If this is only for the current selected item in the quickfix window, that's the Search highlight group on top of the normal quickfix highlighting. You then have to change either one; the Search group will affect search results in other windows, too.
If this is other / special Syntastic highlighting, you best look through all groups in the :hi output to find the bad one.
Overriding
Unless you want to completely switch your colorscheme, you can adapt individual highlight groups via :highlight commands after the :colorscheme command in your ~/.vimrc. Either :hi link to another predefined group, or provide your own ctermfg=... guifg=... etc. color definitions, as described by :help highlight-args.
Syntastic doesn't change (nor cares about) highlighting of the error window. It's a plain quickfix window, with filetype qf. Looking at syntax/qf.vim, the default highlighting is this:
syn match qfFileName "^[^|]*" nextgroup=qfSeparator
syn match qfSeparator "|" nextgroup=qfLineNr contained
syn match qfLineNr "[^|]*" contained contains=qfError
syn match qfError "error" contained
hi def link qfFileName Directory
hi def link qfLineNr LineNr
hi def link qfError Error
Thus, if you see the quickfix window in different colours than the main text, it's because your colour scheme has specifically intended it to look that way. You can override highlighting for qfFileName, qfSeparator, qfLineNr, and qfError to make it more readable, but the better solution IMO would be to use a less broken colour scheme.
Edit: Vim 8.0.641 and later has QuickFixLine.

vim: change line's font color based upon first character in the line?

In vim, I'd like to change a font color for just one line depending on if said line starts (with any preceding tab/space/whitespace) a dash, period, slash, or 'x'. How can I program/configure existing vim to do this?
In Vim, a colorscheme just provides a mapping of highlighting groups (usually generic ones such as Comment, String, though particular syntaxes also define things like vimLineComment) to foreground / background colors and text attributes such as bold or italic. What you want is a custom syntax definition.
:help usr_44.txt introduces writing a syntax file; you can also look to the existing ones in $VIMRUNTIME/syntax/ for inspiration. To highlight lines starting with x:
:syntax match mysyntaxXLine /^x.*$/
:highlight link mysyntaxXLine Error

Replacing vim colors without inventing color scheme

I don't want to learn how to create a new scheme. I just want to replace some color with another color everywhere in default color scheme.
This is how default.vim (default color scheme by Bram Moolenaar) looks like with comments removed:
hi clear Normal
set bg&
hi clear
if exists("syntax_on")
syntax reset
endif
let colors_name = "default"
As you see it doesn't define any colrs it uses whatever the colors used to be (in C code, I guess).
So, how can I replace some color with another color everywhere?
Example: default color scheme highlights some groups of text with color 'ugly' and I want it to highlight it with colour 'neutral'.
Is question clear enough now?
*:hi-default* *:highlight-default*
The [default] argument is used for setting the default highlighting for a
group. If highlighting has already been specified for the group the command
will be ignored. Also when there is an existing link.
Using [default] is especially useful to overrule the highlighting of a
specific syntax file. For example, the C syntax file contains: >
:highlight default link cComment Comment
If you like Question highlighting for C comments, put this in your vimrc file: >
:highlight link cComment Question
Without the "default" in the C syntax file, the highlighting would be
overruled when the syntax file is loaded.
Here is how to replace a color everywhere in Vim. First, use the :highlight command in vim to view a sample of all the predefined color groups. You should also read the output of :help highlight to see the definitions of all the color highlighting groups.
Once you have identified the group you want to change the a candidate replacement group (with a better color), use a command like this:
" Fix the difficult-to-read default setting for search/replace text
" highlighting. The bang (!) is required since we are overwriting the
" DiffText setting. Use the ":highlight" command in vim to see
" alternate color choices if you don't like "Todo" or "StatusLine"
highlight! link IncSearch Todo " Yellow
highlight! link Search StatusLine " Light tan
" Fix the difficult-to-read default setting for diff text highlighting.
" The bang (!) is required since we are overwriting the DiffText
" setting. The highlighting for "Todo" also looks nice (yellow) if you
" don't like the "MatchParen" (Aqua) diff color.
highlight! link DiffText MatchParen " Aqua
" highlight! link DiffText Todo " Yellow
The vim help for highlight shows you can also specify colors as hex RGB like:
:highlight Comment guifg=#11f0c3 guibg=#ff00ff
There is also a lot of good information to be found by using :help syntax.
As always, once you have found the colors you like, you should save them in your ~/.vimrc file (saved in Git, of course!) so they are applied automatically every time you fire up GVim.

Resources