kevinhwang91 / nvim-hlslens

Hlsearch Lens for Neovim
BSD 3-Clause "New" or "Revised" License
748 stars 10 forks source link

[Cross-Plugins] Conflict of NeoClear.lua #56

Closed nyngwang closed 1 year ago

nyngwang commented 1 year ago

Describe the bug I want to use your plugin with my own one https://github.com/nyngwang/NeoClear.lua. If I run :NeoClear and then type n(or N) again to jump to the next(or previous) word, the counter of occurrence will disappear. While I did find a workaround(code provided below), I'm thinking about how to get rid of the workaround code by fixing it upstream.

To Reproduce using nvim -u mini.lua

use {
  'petertriho/nvim-scrollbar', -- This plugin requires your plugin.
  requires = {
    'kevinhwang91/nvim-hlslens',
    config = function ()
      vim.keymap.set('n', 'n', function ()
        vim.cmd([[
          silent! normal! n
          lua require('hlslens').start()
        ]])
      end, NOREF_NOERR_TRUNC)
      vim.keymap.set('n', 'N', function ()
        vim.cmd([[
          silent! normal! N
          lua require('hlslens').start()
        ]])
      end, NOREF_NOERR_TRUNC)
    end
  },
  config = function ()
    require('scrollbar.handlers.search').setup()
    require('scrollbar').setup {}
  end
}

Steps to reproduce the behavior:

  1. Type /require or any other word that occurs many times in your current buffer.
  2. Type n. You will see the occurrence counter of hlslens
  3. Type :NeoClear.
  4. Do. 2. again. You will not see the occurrence counter this time.

Expected behavior I can always see the occurrence counter whether I call :NeoClear or not.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Maybe this is related to my code: https://github.com/nyngwang/NeoClear.lua/blob/main/lua/neo-clear.lua#L10_L11

kevinhwang91 commented 1 year ago

No idea how to fix it. All components of hlslens depend on hlsearch is on.

nyngwang commented 1 year ago

@kevinhwang91 When you finish searching a word and you want to clear its highlighting, would you call :noh? My plugin only calls :noh and that cause the problem: the next time pressing n or N the counter of your plugin disappears.

kevinhwang91 commented 1 year ago

the next time pressing n or N the counter of your plugin disappears.

I tried NeoClear.lua just now, but can't reproduce it. n or N will work again.

nyngwang commented 1 year ago

@kevinhwang91

In addition to :noh, NeoClear.lua will also call:


I tried NeoClear.lua just now, but can't reproduce it. n or N will work again.

So do you mean that both n and N are working without the need to call require('hlslens').start()? If so, I think this might be caused by the interference of more plugins... In my case I have to add these code to make it work:

local NOREF_NOERR_TRUNC = { noremap = true, silent = true, nowait = true }

vim.keymap.set('n', 'n', function ()
  vim.cmd([[
    silent! normal! n
    lua require('hlslens').start()
  ]])
end, NOREF_NOERR_TRUNC)
vim.keymap.set('n', 'N', function ()
  vim.cmd([[
    silent! normal! N
    lua require('hlslens').start()
  ]])
end, NOREF_NOERR_TRUNC)
kevinhwang91 commented 1 year ago

It's your config issue. NeoClear.lua + hlslens with mini config will work in neovim 0.8 in docker.

nyngwang commented 1 year ago

@kevinhwang91 Thanks for your testing. Sorry that I just realized the minimal config(copy-pasted below) in your README.md is actually doing the same thing: that is, calling require('hlslens').start() after n and N is required. Since I was reviewing my old config and I thought my provided code was a hotfix or something and tried to simplify it. Problem solved, great plugin!

require('hlslens').setup()

local kopts = {noremap = true, silent = true}

vim.api.nvim_set_keymap('n', 'n',
    [[<Cmd>execute('normal! ' . v:count1 . 'n')<CR><Cmd>lua require('hlslens').start()<CR>]],
    kopts)
vim.api.nvim_set_keymap('n', 'N',
    [[<Cmd>execute('normal! ' . v:count1 . 'N')<CR><Cmd>lua require('hlslens').start()<CR>]],
    kopts)