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

filetype plugin on

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

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


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>
  • according to the help :nohls does not work from autocommands – Christian Brabandt Oct 7 '15 at 14:01
  • @Christian Brabandt it works for me: search highlighting disappears when I switch to insert mode, and reappears when I return to normal mode. Must be 'cos I'd luckily not read the help [that's a joke] – boobie_goodness Oct 7 '15 at 18:37

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.

  • Ok, using :nohl did the trick and turned it off. I'm going to edit my question with the code from the /etc/vimrc file. I'd like for someone to tell me how I can disable this feature permanently. Thanks! – user53029 Oct 6 '15 at 14:55
  • IMHO hlsearch is too useful to comment out. I'd play with various settings like the au ones mentioned in @boobie_goodness's post till I knew exactly what was causing the issue. – Tyler Abair Oct 7 '15 at 13:45
  • Also, the .vimrc in your home directory isn't the only file that could be setting some funny options. This SU post explains how to run vim without using any system rc files, but the gist is to run vim as vim -u ~/.vimrc file: superuser.com/questions/140913/… – Tyler Abair Oct 7 '15 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.