Is there any way to highlight multiple searches in (g)Vim?

前端 未结 10 814
青春惊慌失措
青春惊慌失措 2020-12-02 06:29

I want to search for multiple strings in Vim/gVim and have them highlighted in different colours. Is there a way of doing this with out-the-box Vim or with a plug-in?

相关标签:
10条回答
  • 2020-12-02 07:00

    MultipleSearch2 is another script which is integrated with vim's search: http://www.vim.org/scripts/script.php?script_id=1183

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

    Yes, out-of-the-box you can use matchadd().

    To add a highlight, eg. for trailing whitespace:

    :highlight ExtraWhitespace ctermbg=grey guibg=grey
    :call matchadd('ExtraWhitespace', '\s\+$', 11)
    

    To view all matches:

    :echo getmatches()
    

    To remove matches use matchdelete(). Eg.:

    :call matchdelete(7)
    
    0 讨论(0)
  • 2020-12-02 07:03
    :%s /red\|green\|blue/
    

    I am not sure about how to keep different colors for different keyword though. Thanks.

    0 讨论(0)
  • Try "Highlight multiple words", which uses matchadd().

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