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.


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.

  • 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 '14 at 11:36
  • @Rmano please explain. My solution (it is taken from my own ~/.vimrc) doesn't change the editor mode. – user280493 Aug 7 '14 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 '14 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. – user280493 Aug 7 '14 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 '14 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 .


Your Answer

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