13
8
I have set hlsearch
in my ~/.vimrc
. This is normally very useful, but it's annoying to have to do :noh
after I do a replace like '<,'>s/$/',/
(which highlights the end of every line after I run it). How do I get vim
to not highlight after replacing like this?
I'm on Ubuntu 9.04 with vim
7.2. I have the same problem on OS X 10.6 (also vim
7.2). Something that would work on both would be desireable.
UPDATE: All the answers I've received are just adding a key mapping to do :noh
(or an equivalent). I really try to avoid custom key behaviors that I would really get used to, but then make me fail miserably without them (e.g. at a friend's computer, etc.). I would like vim
to automatically do :noh
after doing a replacement. That is, I only want hlsearch
when using /
or *
(maybe a few other cases), but not other times.
A little while ago, I started turning off highlighting by default and turning it on when I want it, like you suggested. Still not perfect, but it's better. – Benjamin Oakes – 2010-04-21T16:24:23.310
2I was aware of this option. The issue is that I'm usually not searching for what I want to replace, so it's pointless to highlight in most cases that I replace. However, it's very useful for when I am searching for something, so I don't want it to go completely away. – Benjamin Oakes – 2009-10-29T18:31:12.617
@Benjamin: You did implicitly search for it. That's what :s does. Searches for a pattern and then performs a transformation on the match(es). Using :nohl is the right solution as it turns off the highlight of the current search pattern until the next search is performed. It does this without changing the state of the 'hlsearch' option or affecting the stored value of the previous search term. – jamessan – 2009-12-02T17:47:12.620
2@jamessan: I understand that it's a search and replace. It's just that I don't need it highlighted then. Mostly an annoyance more than anything. – Benjamin Oakes – 2009-12-04T15:31:15.517