kevinhwang91 / nvim-hlslens

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

Nice plugin but isn't working, it's on but not working #68

Closed daUnknownCoder closed 8 months ago

daUnknownCoder commented 8 months ago

Describe the bug My hlsearch is the default one and i don't remember messing that up

-- current config with lazy.nvim
return {
  "kevinhwang91/nvim-hlslens",
  event = { "BufReadPre", "BufNewFile" },
  keys = {
    {
      "n",
      [[<cmd>execute('normal! ' . v:count1 . 'n')<cr>]] .. [[<cmd>lua require("hlslens").start()<cr>]],
    },
    {
      "N",
      [[<cmd>execute('normal! ' . v:count1 . 'N')<cr>]] .. [[<cmd>lua require("hlslens").start()<cr>]],
    },
    { "*", "*" .. [[<cmd>lua require("hlslens").start()<cr>]] },
    { "#", "#" .. [[<cmd>lua require("hlslens").start()<cr>]] },
    { "g*", "g*" .. [[<cmd>lua require("hlslens").start()<cr>]] },
    { "g#", "g#" .. [[<cmd>lua require("hlslens").start()<cr>]] },
  },
  config = function()
    require("hlslens").setup({
      calm_down = true,
      override_lens = function(render, plist, nearest, idx, r_idx)
        local sfw = vim.v.searchforward == 1
        local indicator, text, chunks
        local abs_r_idx = math.abs(r_idx)
        if abs_r_idx > 1 then
          indicator = string.format("%d%s", abs_r_idx, sfw ~= (r_idx > 1) and "" or "")
        elseif abs_r_idx == 1 then
          indicator = sfw ~= (r_idx == 1) and "" or ""
        else
          indicator = ""
        end

        local lnum, col = unpack(plist[idx])
        if nearest then
          local cnt = #plist
          if indicator ~= "" then
            text = string.format("[%s %d/%d]", indicator, idx, cnt)
          else
            text = string.format("[%d/%d]", idx, cnt)
          end
          chunks = { { " ", "Ignore" }, { text, "HlSearchLensNear" } }
        else
          text = string.format("[%s %d]", indicator, idx)
          chunks = { { " ", "Ignore" }, { text, "HlSearchLens" } }
        end
        render.set_virt(0, lnum - 1, col - 1, chunks, nearest)
      end,
    })
  end,
}

Expected behavior My custom highlights

Screenshots image

daUnknownCoder commented 8 months ago

works, turns out i had disabled hlsearch in opts in the long past