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

Status line not updated at once when changing User highlight groups dynamically #4108

Open
lifepillar opened this issue Mar 13, 2019 · 1 comment

Comments

@lifepillar
Copy link
Contributor

The following is contrived code that modifies a highlight group in the status line according the current mode (Normal or something else):

fun! SetMode()
  execute 'hi! link XYZ' (mode() ==# 'n' ? 'Search' : 'Visual')
  return ''
endf

fun! BuildStatusLine()
  return '%{SetMode()}%#XYZ# MODE %*'
endf

set statusline=%!BuildStatusLine()

The above works as I expect (colors change immediately when switching to and from Normal mode). Now, try using a User highlight group instead:

fun! SetMode()
  execute 'hi! link User1' (mode() ==# 'n' ? 'Search' : 'Visual')
  return ''
endf

fun! BuildStatusLine()
  return '%{SetMode()}%1* MODE %*'
endf

set statusline=%!BuildStatusLine()

I would expect this to behave the same as before, but it seems that the status line is not refreshed immediately after switching mode (if I press another key, the status line is updated). I know that this is a minor issue, but shouldn't the two snippets above behave in the same way?

I can reproduce this with Vim 8.1.950 and vim --clean.

@dylnmc
Copy link

dylnmc commented Mar 20, 2019

I haven't tested it recently, but I don't think any of the built-in's work (such as the ones listed in :help 'hi'). I think they are expected to remain more static. Luckily, user-defined highlight groups work.

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

No branches or pull requests

2 participants