RRethy / vim-illuminate

illuminate.vim - (Neo)Vim plugin for automatically highlighting other uses of the word under the cursor using either LSP, Tree-sitter, or regex matching.
2.19k stars 50 forks source link

don't work with highlight yank #107

Closed YuCao16 closed 2 years ago

YuCao16 commented 2 years ago

Describe the bug I was using illuminate and highlightedyank before, but I have now given up on highlightedyank and use neovim build in autocmd as follows:

augroup highlight_yank
    autocmd!
    au TextYankPost * silent! lua vim.highlight.on_yank {higroup=(vim.fn['hlexists']('HighlightedyankRegion') > 0 and 'HighlightedyankRegion' or 'IncSearch'), timeout=750}
augroup END

This code should highlight the whole line, but miss the word highlighted by illuminate:

image

To Reproduce Steps to reproduce the behavior (include minimal init.vim or .vimrc):

  1. Add autocmd to your init.lua
  2. Find a word can toggle illuminate
  3. Double press y

Expected behavior The whole line been highlighted.

RRethy commented 2 years ago

Please provide a minimal init.vim in the future, what you pasted is not minimal nor can be it used in isolation.

Highlight priority is handling internally in Neovim here and uses this value. That's out of scope for this plugin to modify.

silentjay commented 2 years ago

Also having this problem, sadly linking neovims internals isn't much help.

Does anyone have a work around?

serranomorante commented 10 months ago

I tried with neovim internals but got frustrated very quickly. I just added some extra lines to my on_yank highlight autocmd.

This will hide vim-illuminate's highlights while the yanking highlight is visible and show them again when is not.

Not a perfect solution though... because illuminate's highlights take some time to hide completely.

autocmd("TextYankPost", {
  desc = "Highlight yanked text",
  group = augroup("highlightyank", { clear = true }),
  callback = function(event)
    local highlight_timeout = 800
    local illuminate_available = utils.is_available("vim-illuminate")

    if illuminate_available then
      require("illuminate").invisible_buf(event.buf)
      vim.defer_fn(function() require("illuminate").visible_buf(event.buf) end, highlight_timeout + 200)
    end

    vim.highlight.on_yank({
      higroup = "Substitute",
      timeout = highlight_timeout,
      on_macro = true,
    })
  end,
})

utils.is_available is just a helper function to see if vim-illuminate exists in my current instance of neovim.

Edited

Changed my previous approach because it wasn't working when yanking words (yiw)...

rockyzhang24 commented 8 months ago

A workaround here. Works well.

vim.api.nvim_create_autocmd({ 'TextYankPost' }, {
  group = vim.api.nvim_create_augroup('highlight_yank', { clear = true }),
  callback = function()
    local illuminate = require "illuminate"
    illuminate.pause()
    vim.highlight.on_yank({ timeout = 300 })
    illuminate.resume()
  end,
})
serranomorante commented 8 months ago

Apparently no workaround is needed after this recent commit.

Working fine now for me.

RRethy commented 8 months ago

Yea when this issue was first opened we weren't using extmarks at the time.