简体   繁体   English

Vim:搜索不再突出显示 cursor 下的单词

[英]Vim: search no longer highlights word under cursor

I have recently installed Vim on a new computer, and it seems the behaviour of highlighting wrt 'search' has changed.我最近在一台新电脑上安装了 Vim,似乎突出显示“搜索”的行为发生了变化。 When I search for a word (either using / or with * for 'search word under cursor'), the word that the cursor is currently on (so when I jump to the next search result, the highlighting changes) is no longer highlighted.当我搜索一个词时(使用 / 或 * 表示“光标下的搜索词”),cursor 当前所在的词(因此当我跳转到下一个搜索结果时,突出显示会发生变化)不再突出显示。 I'd like for all search results to be highlighted, regardless of where the cursor is.我希望突出显示所有搜索结果,无论 cursor 在哪里。 How do I configure this?我该如何配置? Thanks.谢谢。

Edit: in response to followup questions in an answer below, I can add:编辑:针对以下答案中的后续问题,我可以添加:

  • I'm using Vim 9 on Windows我在 Windows 上使用 Vim 9
  • I'm using the 'darkblue' theme ("colo darkblue" in vimrc)我正在使用 'darkblue' 主题(vimrc 中的“colo darkblue”)
  • Search and CurSearch are as follows: Search和CurSearch如下:

Search xxx term=reverse ctermfg=0 ctermbg=14 guifg=#90fff0 guibg=#0030ff CurSearch xxx term=reverse搜索 xxx term=reverse ctermfg=0 ctermbg=14 guifg=#90fff0 guibg=#0030ff CurSearch xxx term=reverse

However , if (after starting vim), I do 'set background=dark', then CurSearch becomes但是,如果(在启动 vim 之后)我设置了“set background=dark”,那么CurSearch 就变成了

CurSearch xxx links to Search CurSearch xxx 链接到搜索

and the behaviour of keyword highlighting changes to what I want.并且关键字突出显示的行为更改为我想要的。

Now, I used to have 'set background=dark' in my vimrc, but apparently I changed it somewhere in the last few years (it's commented out in the vimrc that I've taken along with me across machines since the late 1990's.).现在,我曾经在我的 vimrc 中设置过“set background=dark”,但显然我在过去几年的某个地方更改了它(它在 vimrc 中被注释掉了,我从 1990 年代末开始就在不同的机器上使用了它。) . I can't find 'background' in the manual any more as an option that can be set though, I'm not sure what's going on with that.我在手册中再也找不到“背景”作为可以设置的选项,但我不确定这是怎么回事。

  • Output of vim --version: vim 的 Output --版本:
> C:\Users\Roel>"c:\Program Files (x86)\Vim\vim90\vim.exe" --version VIM
> - Vi IMproved 9.0 (2022 Jun 28, compiled Jun 28 2022 13:10:49) MS-Windows 32-bit console version Compiled by appveyor@APPVYR-WIN Huge
> version without GUI.  Features included (+) or not (-):
> +acl                +ex_extra           +multi_lang         -tag_any_white
> +arabic             +extra_search       +mzscheme/dyn       -tcl
> +autocmd            -farsi              -netbeans_intg      +termguicolors
> +autochdir          +file_in_path       +num64              +terminal
> +autoservername     +find_in_path       +packages           -termresponse
> -balloon_eval       +float              +path_extra         +textobjects
> +balloon_eval_term  +folding            +perl/dyn           +textprop
> -browse             -footer             +persistent_undo    -tgetent
> ++builtin_terms     +gettext/dyn        +popupwin           +timers
> +byte_offset        -hangul_input       -postscript         +title
> +channel            +iconv/dyn          +printer            -toolbar
> +cindent            +insert_expand      +profile            +user_commands
> +clientserver       +ipv6               +python/dyn         +vartabs
> +clipboard          +job                +python3/dyn        +vertsplit
> +cmdline_compl      +jumplist           +quickfix           +vim9script
> +cmdline_hist       +keymap             +reltime            +viminfo
> +cmdline_info       +lambda             +rightleft          +virtualedit
> +comments           +langmap            +ruby/dyn           +visual
> +conceal            +libcall            +scrollbind         +visualextra
> +cryptv             +linebreak          +signs              +vreplace
> +cscope             +lispindent         +smartindent        +vtp
> +cursorbind         +listcmds           +sodium/dyn         +wildignore
> +cursorshape        +localmap           +sound              +wildmenu
> +dialog_con         +lua/dyn            +spell              +windows
> +diff               +menu               +startuptime        +writebackup
> +digraphs           +mksession          +statusline         -xfontset
> -dnd                +modify_fname       -sun_workshop       -xim
> -ebcdic             +mouse              +syntax             -xpm_w32
> +emacs_tags         -mouseshape         +tag_binary         -xterm_save
> +eval               +multi_byte_ime/dyn -tag_old_static    system vimrc file: "$VIM\vimrc"
>      user vimrc file: "$HOME\_vimrc"  2nd user vimrc file: "$HOME\vimfiles\vimrc"  3rd user vimrc file: "$VIM\_vimrc"
>       user exrc file: "$HOME\_exrc"   2nd user exrc file: "$VIM\_exrc"
>        defaults file: "$VIMRUNTIME\defaults.vim" Compilation: cl -c /W3 /GF /nologo -I. -Iproto -DHAVE_PATHDEF -DWIN32  -DFEAT_CSCOPE
> -DFEAT_TERMINAL -DFEAT_SOUND  -DFEAT_JOB_CHANNEL -DFEAT_IPV6    -DHAVE_SODIUM -DDYNAMIC_SODIUM -DDYNAMIC_SODIUM_DLL=\"libsodium.dll\" /I "C:\libsodium\include" -DWINVER=0x0501 -D_WIN32_WINNT=0x0501
> /source-charset:utf-8 /MP -DHAVE_STDINT_H /Ox /GL -DNDEBUG /arch:IA32
> /Zl /MT /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE
> -DFEAT_MBYTE_IME -DDYNAMIC_IME -DDYNAMIC_ICONV -DDYNAMIC_GETTEXT -DFEAT_LUA -DDYNAMIC_LUA -DDYNAMIC_LUA_DLL=\"lua54.dll\" -DFEAT_PYTHON -DDYNAMIC_PYTHON -DDYNAMIC_PYTHON_DLL=\"python27.dll\" -DFEAT_PYTHON3 -DDYNAMIC_PYTHON3 -DDYNAMIC_PYTHON3_DLL=\"python310.dll\" -DFEAT_MZSCHEME -I "C:\racket\include" -DMZ_PRECISE_GC -DDYNAMIC_MZSCHEME -DDYNAMIC_MZSCH_DLL=\"libracket3m_da32rk.dll\" -DDYNAMIC_MZGC_DLL=\"libracket3m_da32rk.dll\" -DFEAT_PERL -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DDYNAMIC_PERL -DDYNAMIC_PERL_DLL=\"perl532.dll\" -DFEAT_RUBY -DDYNAMIC_RUBY -DDYNAMIC_RUBY_DLL=\"msvcrt-ruby300.dll\" -DRUBY_VERSION=30 -DFEAT_HUGE /Fd.\ObjCULYHRZi386/ /Zi Linking: link /nologo /opt:ref /LTCG oldnames.lib kernel32.lib advapi32.lib shell32.lib gdi32.lib 
> comdlg32.lib ole32.lib netapi32.lib uuid.lib user32.lib  /machine:i386
> libcmt.lib   /nodefaultlib:lua54.lib  /STACK:8388608 
> /nodefaultlib:python27.lib /nodefaultlib:python310.lib    winmm.lib
> WSock32.lib Ws2_32.lib   /PDB:vim.pdb -debug
  • I have not set termguicolors我没有设置 termguicolors

When Googling for 'CurSearch', I found another question on here that deals with exactly my problem: gvim not highlighting searched word where cursor is located (I hadn't found this when searching before posting my question).当谷歌搜索“CurSearch”时,我在这里发现了另一个问题,它正好解决了我的问题: gvim 没有突出显示 cursor 所在的搜索词(我在发布问题之前搜索时没有找到这个)。 However the solution there doesn't help me, as I don't have any custom highlight rules.但是那里的解决方案对我没有帮助,因为我没有任何自定义突出显示规则。

So I looked at darkblue.vim, and there is one place that does hi CurSearch term=reverse.所以我查看了 darkblue.vim,有一个地方是 hi CurSearch term=reverse。 It's only done when s:t_Co >= 0. That variable has value 16777216 for me, which is as expected.它仅在 s:t_Co >= 0 时完成。该变量对我来说具有值 16777216,这是预期的。 I don't understand why the colorscheme would order tests for s:t_Co from highest to lowest though.我不明白为什么 colorscheme 会按照从最高到最低的顺序对 s:t_Co 进行测试。 What I mean is, it starts with if s:t_Co >= 256 (then change a bunch of highlight rules), if s_t_Co >= 16 (then use other settings) and so on.我的意思是,它以 if s:t_Co >= 256(然后更改一堆突出显示规则),if s_t_Co >= 16(然后使用其他设置)等开头。 So it seems that it would always use the last (if s:t_Co > 0), and thus set CurSearch to term=reverse.所以它似乎总是使用最后一个(如果 s:t_Co > 0),因此将 CurSearch 设置为 term=reverse。 But all color schemes do it that way, so I'm probably just misunderstanding.但是所有的配色方案都是这样做的,所以我可能只是误会了。

Finally, I also don't understand why set background=dark would fix my problem.最后,我也不明白为什么 set background=dark 会解决我的问题。

So that's where I'm at.这就是我所在的位置。 Any hints appreciated.任何提示表示赞赏。

Historically, Vim didn't make the current match visible but it introduced a new highlight group specifically for highlighting the current match: CurSearch .从历史上看, Vim 并没有使当前匹配项可见,但它引入了一个专门用于突出显示当前匹配项的新高亮组: CurSearch It is linked to Search by default so it is expected to look just like any other match by default.它默认链接到Search ,因此默认情况下它看起来就像任何其他匹配项一样。 Here, the current match is the second:在这里,当前匹配是第二个:

定义

If you give it its own styling attributes or link it to another highlight group, you can get a separate highlight for the current match:如果你给它自己的样式属性或将它链接到另一个高亮组,你可以为当前匹配获得一个单独的高亮:

关联

Now, it might be a bug in Vim or in the colorscheme you are using.现在,它可能是 Vim 或您正在使用的配色方案中的错误。 Adding the full output of $ vim --version to your question, mentioning what colorscheme you are using, and if you use :help 'termguicolors' might help us narrow down the issue.将完整的 output 的$ vim --version添加到您的问题中,提及您使用的颜色方案,如果您使用:help 'termguicolors'可能会帮助我们缩小问题范围。 Adding a screenshot might help, too.添加屏幕截图也可能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM