How to remove highlight group? - vim

I'm trying to remove the jsonCommentError highlight group. On startup I see the highlight group is active by running :hi jsonCommentError.
:hi jsonCommentError
jsonCommentError xxx links to Error
I tried to remove it with :hi clear jsonCommentError and :hi jsonCommentError NONE but this didn't work, and there is no change when I run :hi jsonCommentError.
I guess :hi clear didn't work because the highlight group wasn't added by the user, but I don't know why :hi NONE didn't work.

You can't really remove the group. Only to make it transparent.
hi clear removes group's own highlighting colors. hi link sets group's link target (that always has a preference over group's own colors).
Which one you need, it depends. But it never hurts to do both at the same time:
hi clear jsonCommentError
hi! link jsonCommentError NONE
Also in this case, you may want to switch off all error highlighting at once (see :h json.vim):
let g:vim_json_warnings = 0

Related

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: Using custom highlight groups in statusline

When customising my vim statusline, I'm able to use the following syntax to make use of the highlight group User1:
set statusline+=%1*
Let's say I have some custom highlights like:
highlight StatusLineStyle ctermbg=34 ctermfg=15 guibg=#00af00 guifg=#ffffff
How can I make use of those custom syntax colourings in my statusline?
Similar to the %N*, there's %#HLname# for custom highlight group names. Actually, it's documented right above that (at :help 'statusline'). So, for your example, use
:set statusline+=%#StatusLineStyle#
Alternatively, you could use the User1..9 styles, and link your highlight group to it:
:highlight link User1 StatusLineStyle
It's explained in :help 'statusline', just above the part on %1*:
# - Set highlight group. The name must follow and then a # again.
Thus use %#HLname# for highlight group HLname. The same
highlighting is used, also for the statusline of non-current
windows.
So…
set statusline+=%#StatusLineStyle#%f#

vim remove highlight (not search highlight)

This is a screen of vim editing .bash_profile. It seem to have used some weird highlighting that I didn't explicitly turn on (e.g. around GaF)
using nohl doesn't help since I didn't initiate a search. I also tried using 'syntax off', but that just made all the font/text colours white, but the highlights were still in place.
Anyone know what this is, or how to turn it off?
Thanks
remove all highlighting.
hi clear
you can find out the group name and
hi clear group
to disable highlighting on one group
You need to find out which syntax group causes the highlighting. :syn list shows all active groups, but it's easier when you install the SyntaxAttr.vim - Show syntax highlighting attributes of character under cursor plugin. When you have the name of the offending syntax group, you see to which highlight group this links to. Then check your colorscheme for its definition:
:highlight <groupname>
For me, I had an issue like this every time I opened the help window for any command. As the user #snowbound said in the comments, doing :set nospell solved the issue.
I want to expand on Kent and Ingo Karkat's answers for those that don't wish to install a plugin.
To find out the name of the highlight group in questions, you can use this:
" call `:exec SynGroup()` to show the highlight group under the cursor
function! SynGroup()
let l:s = synID(line('.'), col('.'), 1)
echo synIDattr(l:s, 'name') . ' -> ' . synIDattr(synIDtrans(l:s), 'name')
endfun
(My vimscript is bad, and I copied this from somewhere on the internet long ago. Thank you to that person.)
Anyway, as Kent said, you can use
hi clear <group>
to disable the highlighting for that group.
For example, :exec SynGroup() in vimscript comments gives you
vimLineComment -> Comment
Then you can use
hi clear Comment
To remove the highlighting.

Spelling errors hidden while highlighting line in vim

When there's a misspelling (with set spell), it highlights it red (good!), but when the line is highlighted as my current line the red goes away (bad). Removing set cul fixes the problem, but how do I keep the word marked red while being highlighted? I may have multiple words misspelled on a line and also while typing the misspellings are hidden until I go to the next which kinda sucks.
vimrc: https://gist.github.com/OscarGodson/d1b05d52df4ff160b891
colorscheme: https://github.com/tomasr/molokai
1) one could change the vim color scheme, or the SpellBad highlight scheme; one example of the second case is to add in vimrc the following,
hi clear SpellBad
hi SpellBad cterm=bold
2) (not a solution) someone might find 'spell checking while composing' is a bit annoying / distracting and prefer switching the spell checking off until they finish writing the article.
The problem is that the cursorline highlighting has priority over the syntax highlighting (spell errors belong to that), and that cannot be changed. (You can only specify the priority with the newer matchadd() functions.)
I've once raised this issue for error highlighting, but nothing came out of it. (I'd still like to implement a patch for that one day.)
The problem is only about overlap of background highlighting; in GVIM, most color schemes use the undercurl attribute to avoid that issue. In the console, you can only change the highlighting to foreground color, italic or bold attributes to work around it.
workaround
One clever workaround involves swapping the foreground and background colors while adding the reverse attribute: Turn
hi SpellBad cterm=NONE ctermbg=red ctermfg=white
to
hi SpellBad cterm=reverse ctermbg=white ctermfg=red
These two changes cancel each other out normally, but on a CursorLine, the foreground color now contributes to the coloring, turning hard-to-read white-on-cursorline to red-on-cursorline.
Curiously, and jumping off of both answers from the other posters, adding the following in my vimrc made my red background persist accidentally due to my terminal not being able to fulfill the "italic" switch because it can't mix font types like that (I think). I stuck it in the section of my vimrc that is tested for gvim because gvim underlines my spelling mistakes without issue. Give it a try!
if has("gui_running")
#all my gvim settings
else #we're in terminal
hi clear SpellBad
hi SpellBad cterm=bold,italic ctermfg=red
endif

Reload Vim highlight setting and colorscheme

If I change Vim's highlight setting, how do I "reload" it for colorschemes to take effect?
So, in my case, I remove highlight's cursor line number
se hl-=N:CursorLineNr
Changing highlight from
highlight=8:SpecialKey,#:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:Mor
eMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:Vert
Split,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:D
iffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:Spel
lCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,
#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn
to
highlight=8:SpecialKey,#:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:Mor
eMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v
:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffCh
ange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRar
e,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:
TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn
(I've emphasized the change.)
But the cursor line number is still "highlighted"!
Changing highlight doesn't update the colorscheme—so how do I "force" an update? I've tried setting syntax coloring off then on again and changing colorschemes to no avail.
If you want to reset/clear a highlight-group, you could use :hi cmd.
in your case, try with:
:hi CursorLineNr NONE #this will disable the hl setting for the given group
:hi clear CursorLineNr #this will set the given group's highlight setting to default.
:h hi to see detail
if you want to reload your colorscheme, you could :color xxx
hope it helps

Resources