简体   繁体   中英

Vim: When sourcing vimrc, last search hl re-appears

The title pretty much says it all. When I :source $MYVIMRC or :source ~/.vimrc , the last search re-appears. I can easily turn this off again with :noh , but it re-appears every time I :source .

This persists

  • With a fresh .vimrc
  • After deleting current MacVim install and downloading a fresh copy
  • In iTerm using vim

I have checked in every file listed with :version , and other than my .vimrc , the only other file listed that isn't empty is $VIM/vimrc - which has only:

set nocompatible  
set backspace+=indent,eol,start  
set langmenu=none  

I also tried the nuclear method: disable all plugins and pretend it's a fresh install:

mv .vim .vim-old  
mv .vimrc .vimrc-old  
touch .vimrc  
echo "set hlsearch" > .vimrc  

The issue still occurs.

I'm pretty stumped as I don't recall this being the normal behavior; any help would be much appreciated.

Credit to @AndyRay - I was misusing noh to get rid of the last search's highlighting, when instead I should be overriding the search term with :let @/ = "" .

See: Vim clear last search highlighting

Going off what Josh was getting at. Add the following to your ~./vimrc :

" higlight search but not when sourcing .vimrc
set hls
let @/ = ""

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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