Get rid of Vim's highlight after searching text

前端 未结 8 2090
梦如初夏
梦如初夏 2020-12-02 08:37

In VIM, after finding text with \"/\" command, that text remains highlighted.

What is the command to remove that? I don\'t want to remove highlighting capability at

相关标签:
8条回答
  • 2020-12-02 09:00

    I have this in my .vimrc:

    map <leader>h :set hlsearch!<cr>
    

    So when I type:

    \h
    

    It toggles highlighting on/off.

    0 讨论(0)
  • 2020-12-02 09:03

    :noh will get rid of highlighted text.

    0 讨论(0)
  • 2020-12-02 09:04

    Completely disable search highlights

    :set nohlsearch
    

    Clear until next search

    :nohlsearch
    

    or :noh for short. This clears highlights until a new search is performed or n or N is pressed


    Clear on pressing custom map

    • Clear highlights on hitting the ESC key

      nnoremap <esc> :noh<return><esc>
      
    • Clear highlights on pressing \ (backslash) twice

      nnoremap \\ :noh<return>
      
    0 讨论(0)
  • 2020-12-02 09:08

    If you don't want to remove highlighting one of the best ways is to clear the search register, unless of course you need the search items later. This will prevent you from having to re-enable the highlighting and(Edit: noh does not permanently disable highlighting) prevent you from accidentally jumping around. This is how I have mine setup:

    nmap <silent> ,/ :let@/=""<CR>

    What this does is map the key sequence ,/ in normal mode to clear the search register @/ by setting it to an empty string. This is just an alternative to what has already been stated.

    0 讨论(0)
  • 2020-12-02 09:10

    In addition to “clear the search register”, you can even reset the search register to its previous value:

    command! -nargs=* -range S
    \ let atslash=@/|exe ':'.<line1>.','.<line2>.'s'.<q-args>|let @/=atslash
    

    However:
    - this does not reset the previous status of :hls. I do not believe this to be possible in general.
    - this defines a new command, :S, to use in place of :s. You can use a cabbrev to map one to the other, but this will break when you add a range to the substitute command.

    0 讨论(0)
  • 2020-12-02 09:12

    Type this:

    :noh
    
    0 讨论(0)
提交回复
热议问题