machakann / vim-highlightedyank

Make the yanked region apparent!
844 stars 22 forks source link

Doesn't behave correctly with tagalong.vim #47

Closed Racle closed 3 years ago

Racle commented 3 years ago

When this plugin and AndrewRadev/tagalong.vim are enabled, vim-highlighedyank highlights tag when going to insert mode.

Ex. I got

<div className='classname'></div>

and move cursor over N and press i, highlighedyank highlights <div className='classname'> part. And same thing when going back to normal mode with ctrl + c

Using NVIM v0.4.4 (same issue with version 0.5).

Minimal reproducible test config (with vim-plug installed):

call plug#begin(stdpath('data') . '/plugged')
  Plug 'andrewradev/tagalong.vim'
  Plug 'machakann/vim-highlightedyank'
call plug#end()

Not sure if this is issue with vim-highlightedyank, tagalong or something else. This also happens with CocAction('doHover').

First thing I can think is that highlightedyank probably uses some event and those also trigger that event they select words under cursor (?).

machakann commented 3 years ago

Thank you for your report!

This problem happened simply because tagalong.vim do yank a text. (I also tried to check coc.nvim but it was too complex to me...) As you guess, the vim-highlightedyank hooks the highlighting operation whenever a text yanked by using TextYankPost event. But our difficulty is that there is no way to judge who yanked the text; man or machine?

I have two solutions here. One is to use the key mapping <Plug>(highlightedyank). It automatically stops using the TextYankPost event and highlights text only when you press y. This key mapping actually is not quite clean internally, just kept for old vim which doesn't have TextYankPost event. However, it will circumvent this problem at least.

map y <Plug>(highlightedyank)

Another solution is to send a small PR for tagalong.vim to use :noautocmd, I think if this line is modified to exec 'silent noautocmd normal! '.a:motion.'"zy', then the problem would be solved. This function just aimed at obtaining a text on the buffer, I think it doesn't intend to trigger any auto command events.

Racle commented 3 years ago
map y <Plug>(highlightedyank)

This seems to be working perfectly so far. Thank you for very fast response!

And for second solution, I tested that and it seems to be working also.

I created PR and explained situation. This could be even better solution as it might impact other users also.