Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

When I do search in gVim (package gnome-vim), the search results are highlighted. How can I turn-off this highlighting when I don't need it any longer? Now it looks like persistent.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

You can disable search results highlighting by command :nohl. If you want to have this command under one keystroke, put the following lines into your ~/.vimrc configuration file:

" press F8 to turn the search results highlight off
noremap <F8> :nohl<CR>
inoremap <F8> <C-o>:nohl<CR>

Now you can press F8 to toggle search result highlighting on and off in both edit and insert mode.

share|improve this answer
2  
+1, but wouldn't inoremap <F8> <C-o>:nohl<CR> be better? So it will leave you in the same input mode where you were... –  Rmano Aug 7 at 11:36
    
@Rmano please explain. My solution (it is taken from my own ~/.vimrc) doesn't change the editor mode. –  Mikołaj Bartnicki Aug 7 at 11:45
1  
CTRL-o is the command to enter in normal mode for just one command, and then go back to input. In your macro, you exit input mode, and the you do an "append". So for example if you are inserting before the first caracter of a line (go to the start of the line and press "i"), with your macro after pressing F8 you will be inserting after the first character of the row (the result of "a"). With my version you will just continue inserting before or after, whatever you were doing before pressing F8. –  Rmano Aug 7 at 11:53
1  
@Rmano You are right, I just tried your 'test scenario' and it works like you said. Thanks for pointing this out, I will update my ~/.vimrc as well as my answer here. –  Mikołaj Bartnicki Aug 7 at 11:58
    
For the record this cannot turn highlighting back on. This only turns highlighting off (temporarily). The next search will highlight again automatically though. –  Etan Reisner Aug 7 at 15:06

You can edit your .vimrc file :

To disable the highlighting temporarily, write :set nohlsearch and delete :set hlsearch

Then save and exit .

share|improve this answer
    
This is a valid answer, although it's a bit roundabout. –  TankorSmash Aug 7 at 14:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.