qxxxb / vim-searchhi

Highlight the current search result differently
GNU General Public License v3.0
47 stars 6 forks source link

Is there a way to clear highlight all matches even the last chosen one? #10

Closed roachsinai closed 4 years ago

roachsinai commented 4 years ago

The last chosen one keep highlight even I change the content of other lines in insert mode.

Thanks in advance!

roachsinai commented 4 years ago

My setting is:

Plug 'timakro/vim-searchant'
Plug 'qxxxb/vim-searchhi'
Plug 'osyo-manga/vim-anzu'

nmap n <Plug>(searchhi-n)
nmap N <Plug>(searchhi-N)
nmap * <Plug>(searchhi-*)
nmap g* <Plug>(searchhi-g*)
nmap # <Plug>(searchhi-#)
nmap g# <Plug>(searchhi-g#)
nmap gd <Plug>(searchhi-gd)
nmap gD <Plug>(searchhi-gD)

vmap n <Plug>(searchhi-v-n)
vmap N <Plug>(searchhi-v-N)
vmap * <Plug>(searchhi-v-*)
vmap g* <Plug>(searchhi-v-g*)
vmap # <Plug>(searchhi-v-#)
vmap g# <Plug>(searchhi-v-g#)
vmap gd <Plug>(searchhi-v-gd)
vmap gD <Plug>(searchhi-v-gD)

let g:searchhi_user_autocmds_enabled = 1
let g:searchhi_redraw_before_on = 1

augroup searchhi
    autocmd!
    autocmd User SearchHiOn AnzuUpdateSearchStatusOutput
    autocmd User SearchHiOff echo g:anzu_no_match_word
augroup END
augroup searchhi
    autocmd!

    autocmd User SearchHiOn
        \ set guicursor=
            \c-sm:block,i-ci-ve:ver25,r-cr-o:hor20,
            \n-v:block-blinkwait20-blinkon20-blinkoff20 |
        \ AnzuUpdateSearchStatusOutput

    autocmd User SearchHiOff set guicursor& | echo g:anzu_no_match_word
augroup END

let g:searchhi_clear_all_asap = 1

nmap / <Plug>(searchhi-/)
nmap ? <Plug>(searchhi-?)

vmap / <Plug>(searchhi-v-/)
vmap ? <Plug>(searchhi-v-?)
qxxxb commented 4 years ago

Sorry I don't think I understand. Could you be more specific? If you want to turn off highlighting in insert mode you can try:

let g:searchhi_clear_all_autocmds = 'InsertEnter'
let g:searchhi_update_all_autocmds = 'InsertLeave'
roachsinai commented 4 years ago

If you want search highlighting to be cleared as soon as the cursor moves, use this:

let g:searchhi_clear_all_asap = 1

What I expected is when I move left or right clear the highlight, but seems the choosen match highlight not cleared as the quote saying.

Check below image, the search word is class, but highlight still there even cursor is on word Solution:

Screen Capture_select-area_20201014092259

qxxxb commented 4 years ago

I think the problem is that you have vim-searchant installed as well. Also you seem to be redefining searchhi autocmds. Here are the changes I would suggest:

-Plug 'timakro/vim-searchant'
Plug 'qxxxb/vim-searchhi'
Plug 'osyo-manga/vim-anzu'

nmap n <Plug>(searchhi-n)
nmap N <Plug>(searchhi-N)
nmap * <Plug>(searchhi-*)
nmap g* <Plug>(searchhi-g*)
nmap # <Plug>(searchhi-#)
nmap g# <Plug>(searchhi-g#)
nmap gd <Plug>(searchhi-gd)
nmap gD <Plug>(searchhi-gD)

vmap n <Plug>(searchhi-v-n)
vmap N <Plug>(searchhi-v-N)
vmap * <Plug>(searchhi-v-*)
vmap g* <Plug>(searchhi-v-g*)
vmap # <Plug>(searchhi-v-#)
vmap g# <Plug>(searchhi-v-g#)
vmap gd <Plug>(searchhi-v-gd)
vmap gD <Plug>(searchhi-v-gD)

let g:searchhi_user_autocmds_enabled = 1
let g:searchhi_redraw_before_on = 1

-augroup searchhi
-    autocmd!
-    autocmd User SearchHiOn AnzuUpdateSearchStatusOutput
-    autocmd User SearchHiOff echo g:anzu_no_match_word
-augroup END
augroup searchhi
    autocmd!

    autocmd User SearchHiOn
        \ set guicursor=
            \c-sm:block,i-ci-ve:ver25,r-cr-o:hor20,
            \n-v:block-blinkwait20-blinkon20-blinkoff20 |
        \ AnzuUpdateSearchStatusOutput

    autocmd User SearchHiOff set guicursor& | echo g:anzu_no_match_word
augroup END

let g:searchhi_clear_all_asap = 1

nmap / <Plug>(searchhi-/)
nmap ? <Plug>(searchhi-?)

vmap / <Plug>(searchhi-v-/)
vmap ? <Plug>(searchhi-v-?)
roachsinai commented 4 years ago

That works, thanks a lot for your reply.

qxxxb commented 4 years ago

No problem!