In some circumstances, the search hit under the cursor has wrong CurSearch set
roel-v opened this issue · 13 comments
Followup from https://stackoverflow.com/questions/74473619/vim-search-no-longer-highlights-word-under-cursor .
Basically, in vim9 with the darkblue colorscheme (although the same happens with blue, desert and koehler - haven't tried others but I think it's universal), when hlsearch is set, the search hit under the cursor isn't highlighted. This is because CurSearch is set to term=reverse, instead of linking to 'Search' as it should. Strangely, when doing 'background=dark' manually after startup, CurSearch is set correctly and the problem disappears.
I tried with a blank vimrc (by starting gvim.exe with -u NONE) and then it works correctly, so it has to have something to do with the way my vimrc interacts with the vim9 way of defining color schemes (since this worked correctly for vim versions before 9 for me).
I tried adding colo=darkblue as the last line in my vimrc, that didn't help.
I also tried 'bisecting' my vimrc by putting 'finish' statements in, to pinpoint which line causes the problem to appear. If I put 'finish' before the "colo darkblue" line, everything works fine (well I get the default color scheme of course, but the highlighting behaviour is OK). If I put it right after 'colo darkblue', I get the color scheme but wrong behaviour.
So then I put this at the top of the vimrc:
colo darkblue
set hlsearch
finish
and I also tried with the first two lines swapped, but both gave me the wrong result. So I feel that I've pretty much ruled out any other parts of my vimrc to be the culprit.
At this point I can't really think of anything else that I have wrong in my own setup to be the problem. Any pointers appreciated.
What is the vim version?
:version
in vim should show smth like:
Included patches: 1-891
-
In GUI Vim with
darkblue
, the expected value ofhlget('CurSearch', 1)
is:[{'id': 8, 'ctermfg': '0', 'name': 'CurSearch', 'term': {'reverse': v:true}, 'ctermbg': '14', 'guibg': '#0030ff', 'guifg': '#90fff0'}]
-
term=<any value>
is not supposed to have any effect in GUI Vim.
@roel-v could you show us what you get with hlget('CurSearch', 1)
?
:let @+ = hlget('CurSearch', 1)->string()
When I start gvim (with my regular vimrc) the value you requested is [{'id': 8, 'name': 'CurSearch', 'term': {'reverse': v:true}}] . Even when the first 3 lines of my vimrc are
colo darkblue
set hlsearch
finish
In both cases, if I do :colo darkblue, manually after startup, it becomes [{'id': 8, 'ctermfg': '123', 'name': 'CurSearch', 'term': {'reverse': v:true}, 'ctermbg': '27', 'guibg': '#0030ff', 'guifg': '#90fff0'}] .
@habamax I don't see those lines in :version . All I see is
@VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jun 28 2022 13:09:53)
MS-Windows 32-bit GUI version with OLE support
Compiled by appveyor@APPVYR-WIN
Huge version with GUI. Features included (+) or not (-):
and then a bunch of vim and compiler flags like in my stackexchange post.
Could you open :e $VIMRUNTIME/colors/darkblue.vim
and paste here first several lines?
" Name: darkblue
" Description: For those who prefer dark background
" Author: Original author Bohdan Vlasyuk <bohdan@vstu.edu.ua>
" Maintainer: Original author Bohdan Vlasyuk <bohdan@vstu.edu.ua>
" Website: https://github.com/vim/colorschemes
" License: Same as Vim
" Last Updated: Fri 02 Sep 2022 09:40:36 MSK
" Generated by Colortemplate v2.2.0
set background=dark
hi clear
let g:colors_name = 'darkblue'
let s:t_Co = exists('&t_Co') && !has('gui_running') ? (&t_Co ?? 0) : -1
Could you open
:e $VIMRUNTIME/colors/darkblue.vim
and paste here first several lines?" Name: darkblue " Description: For those who prefer dark background " Author: Original author Bohdan Vlasyuk <bohdan@vstu.edu.ua> " Maintainer: Original author Bohdan Vlasyuk <bohdan@vstu.edu.ua> " Website: https://github.com/vim/colorschemes " License: Same as Vim " Last Updated: Fri 02 Sep 2022 09:40:36 MSK " Generated by Colortemplate v2.2.0 set background=dark hi clear let g:colors_name = 'darkblue' let s:t_Co = exists('&t_Co') && !has('gui_running') ? (&t_Co ?? 0) : -1
Awesome, this fixes my issue. (I only updated the let s:t_Co line, the first two lines are already in there, but I assume this is what you meant for me to do). I'm not sure exactly as to what this line is meant to be doing in its original form, or why everything works if I manually do set background=dark fixes things too, but this at least makes things work for me for now. Is this something that should be merged upstream or is this an issue from a conflict with something else that is specific for me?
It is already upstream for a month or two.
Closing as this is fixed in recent vim versions.
@roel-v you can grab latest vim for windows here: https://github.com/vim/vim-win32-installer/releases
Oh OK, thank you both for the time you spend on this. It didn't even occur to me that this could be an issue that would be fixed in a newer release.
That is why we were asking about the version you use.
:-)