Skip to content
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

Merged
merged 2 commits into from
Aug 7, 2016
Merged

Fix :GoSameIds for light background, GUI, and after changing colour schemes #983

merged 2 commits into from
Aug 7, 2016

Conversation

arp242
Copy link
Contributor

@arp242 arp242 commented Aug 1, 2016

This does three things:

  • For light backgrounds the "highlighted" text is typically the same colour as
    the normal text: 2016-08-01-060201_1920x1080_scrot
    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.

  • And it sets the guifg/guibg parameters, otherwise nothing gets highlighted when using Gvim...

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()
Copy link
Owner

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?

Copy link
Contributor Author

@arp242 arp242 Aug 2, 2016

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).

Copy link
Owner

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?

Copy link
Contributor Author

@arp242 arp242 Aug 2, 2016

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...

Copy link
Owner

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 ?

Copy link
Contributor Author

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 the colorscheme 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.

@bhcleek
Copy link
Collaborator

bhcleek commented Aug 5, 2016

This would be great. I change my colorscheme using :colorscheme often to accommodate people that are looking at my screen for one reason or another.

@fatih fatih merged commit 37b9518 into fatih:master Aug 7, 2016
@fatih
Copy link
Owner

fatih commented Aug 7, 2016

Thanks @Carpetsmoker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants