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

前端 未结 10 853
青春惊慌失措
青春惊慌失措 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: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)
    

提交回复
热议问题