Vim
Vim copied to clipboard
Highlighted search results loses highlighting after switching to another tab and back
Describe the bug Highlighted search results loses highlighting after switching to another tab and back to initial where searching occurred.
To Reproduce Steps to reproduce the behavior:
- Add/use/have these lines in settings.json (colors can be anything, but visible):
"vim.hlsearch": true,
"vim.searchHighlightColor": "#ffff88",
- Open several files in several tabs;
- Search for any word that is in file, with any type of vim search, like with
/
or?
in command line or with*
in normal mode while cursor is on the necessary word (word becomes highlighted with color defined in settings); - Swtch to any other tab and back to the initial one where search happened, bug happens with any type of switching, i.e. with mouse or
ctrl+tab
/ctrl+shift+tab
or with:tabn
/:tabp
commands; - See that searched word is not highlighted anymore + highlighting disappears for other tabs if searched word exists there too. In addition
n
/shift+n
finds next/previous occurances, but w/o highlighting.
Expected behavior
Searched word should stay highlighted in all open tabs where word exist until other search occurs or until :noh
command is executed;
Environment (please complete the following information):
- Extension (VsCodeVim) version: 1.25.2
- VSCode version: 1.78.2
- OS: Ubuntu 20.04.4 (Linux x64 5.4.0-148-generic)
- OS: macOS Monterey 12.5.1
Additional context
Important to mention - running any command or empty command (:
+ return
) or even canceling empty command (:
+ esc
) restores highlighting, unitl next switching between tabs.
This is the one that bugs me:
In addition n/shift+n finds next/previous occurances, but w/o highlighting.
The first matched word is highlighted according to "vim.searchMatchColor", but pressing n/shift+n just removes the current match highlight, but jumps correctly.
I merged this PR and roughly used it, but found two issues:
- When I searched in tab 1, the highlighting was normal. When I switched to tab 2, the same characters were highlighted normally, but when I switched back to tab 1, the highlighting disappeared;
- When I search for the fourth character in tab 1, in tab 2, the cursor is on the first character and the current selection is highlighted on the fourth character
My PR simply addresses highlighting the current match, and doesn't address the tab-switching aspect. I think the highlighting would be accurate again if you jump to the next match and back (n -> N). All though not optimal, my aim was to address the second part of OP's point 5, as that was the one that bugged me the most.
As for the tab switching I didn't really look into it that much, but I assume a call to updateSearchHighlights
in the proper place could go a long way, I'll see if I can do something.
From some brief testing it appears that mode is reset to normal mode when switching views, as the ModeHandler
is individual per document. Once you do enter search mode again, highlights are corrected. Fixing it would require that search mode persists when switching tab while in search mode, which is something that might be feasible, but not something I think I'll spend time on. To be fair I think that going into normal mode when I switch tab is desirable over staying in search mode (not that there is a big difference).
To be fair I think that going into normal mode when I switch tab is desirable over staying in search mode (not that there is a big difference).
I almost got used to run empty command to "turn on" highlighting in other tab. Other thing is that I have started doing so in ordinary vim. Which is completely not necessary. Ordinary vim keeps highlighting searched text across buffers/tabs/splits/etc till user runs :noh
command.
Probably might use something like map <C-Tab> :tabn | noh | set hls <Enter>
(converted to vscodevim configs) as workaround.
From some brief testing it appears that mode is reset to normal mode when switching views, as the
ModeHandler
is individual per document. Once you do enter search mode again, highlights are corrected.
BTW not really.
Highlights are corrected even if I run empty command (:
+ enter
) or even if I cancel empty command (:
+ esc
). So looks like problem is not only in ModeHandler
being individual per document.
Out of sudden - highlighting disapperas even when I change zoom level (cmd
+-
and cmd
+=
on mac).
Also highlighting restores with going into insert mode and starting typing anything.