1

I ssh to a server then sudo to get root. In the shell my cursor blinks as a yellow block. When I open a file with vim if the text is the same color as my cursor the whole word is blocked out in yellow. The kicker is that it only happens with certain words in the file, not all of them. Really weird. I also noticed that I can be typing along in Vim, only to have the word I am typing block out to yellow, then I can't see my typed word any longer. Anyone ever come across this behavior before and how to fix it? As a test I ssh'ed from another server to the one I experienced the issue on and saw the same problem, so that rules out a problem in my local environment.

UPDATE - I can now confirm that its somehow tied to a history cache. If I open a file in Vim the words that turn into a yellow block are only the ones I have searched for in a previous file, or using a regex within the VIM. This is very strange.

What lines below do I need to comment out to turn off highlighting on the last used search pattern?

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif

filetype plugin on

if &term=="xterm"
set t_Co=8
set t_Sb=^[[4%dm
set t_Sf=^[[3%dm
endif

I assume its "set hlsearch" is the one I need to comment out?

user53029
  • 191

2 Answers2

4

To disable search highlighting permanently, add

set nohlsearch

in your .vimrc

You can also change the search highlighting following various events

au InsertEnter * :setlocal nohlsearch
au InsertLeave * :setlocal hlsearch

Or a quick way to toggle search highlighting:

inoremap <silent><leader>l  <c-o>:set hlsearch! hlsearch?<CR>
noremap <silent><leader>l  :set hlsearch! hlsearch?<CR>
1

Perhaps VIM is highlighting search results due to some plugin, vimrc setting, or behavior that's too obscure for me to be familiar with. Next time this happens, try :nohl. That's how I get VIM to stop highlighting search results after I'm done with /blah, and it will tell us if this is VIM's highlighting behavior or not.