-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix :GoSameIds for light background, GUI, and after changing colour schemes #983
Conversation
This does two things: - For light backgrounds the "highlighted" text is typically the same colour as the normal text. So use the `background` setting to set a more appropriate colour. I know I can set my own colour, but it would IMHO be better if it just works by default. - The second issue is that most (if not all) colour schemes do this at the start: " Remove all existing highlighting and set the defaults. hi clear Which resets all custom highlight groups (except for `:hi link`). So just using a "bare" `:hi ctermfg=...` won't work after changing colour schemes: :hi goSameId goSameId xxx term=bold cterm=bold ctermfg=0 ctermbg=121 :colorscheme default :hi goSameId goSameId xxx cleared The solution is to hook into the `ColorScheme` autocommand.
|
||
augroup vim-go-hi | ||
autocmd! | ||
autocmd ColorScheme * call s:hi() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we apply ColorScheme to all files? And why do we have it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern for the ColorScheme
autocommand is matched against the colour scheme name, not the file name (see :help ColorScheme
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alrigth, back to my question. Why do we need to call this automatically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's needed because using :colorscheme foo
will reset all custom highlight groups − see the message above:
:hi goSameId
goSameId xxx term=bold cterm=bold ctermfg=0 ctermbg=121
:colorscheme default
:hi goSameId
goSameId xxx cleared
It's a bit ugly, but as far as I know there's no "clean" way to avoid this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to understand the case. So you mean we have to add this for users who override it? colorscheme
is only called once in vimrc
. Or is this for people who dynamically change the colorscheme ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few different scenarios:
- Perhaps the most common case is when you reload the vimrc file with
:source ~/.vim/vimrc
. This will run thecolorscheme
command but won't re-run the syntax files (you can use:e
to fix this though, but it's annoying). - I've seen some people use different colour schemes for different filetypes − this autocommand will be run after the syntax file and there is no real way to fix this other than than the above
ColorScheme
autocommand. - As you mentioned, it helps people who change colour schemes while Vim is running. I know some people who like to switch between a dark and light version depending on ambient light conditions. Again,
:e
will fix this, but it's annoying.
This would be great. I change my colorscheme using |
Thanks @Carpetsmoker |
This does three things:
For light backgrounds the "highlighted" text is typically the same colour as
the normal text:
So use the
background
setting to set a more appropriate colour.I know I can set my own colour, but it would IMHO be better if it just
works by default.
The second issue is that most (if not all) colour schemes do this at the
start:
Which resets all custom highlight groups (except for
:hi link
). So justusing a "bare"
:hi ctermfg=...
won't work after changing colour schemes:The solution is to hook into the
ColorScheme
autocommand.And it sets the
guifg
/guibg
parameters, otherwise nothing gets highlighted when using Gvim...