kevinhwang91 / nvim-hlslens

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

Jump to last search when doing :s/ #60

Closed AckslD closed 1 year ago

AckslD commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

If I first search for something, let's say for foo in the following file:

foo
bar

then I clear the search and move to the line with bar and I start typing :s/fo to replace something on the second line (which does not exist in this case), then the cursor jumps to the first line which seems to be caused by hlslens.

To Reproduce using nvim -u mini.lua


    use {
        'kevinhwang91/nvim-hlslens',
        keys = '/',
        module = 'hlslens',
        setup = 'require("plugin_settings.hlslens").setup()',
        config = 'require("plugin_settings.hlslens").config()',
    }

with

local M = {}

M.setup = function() -- {{{
    local noremap = {noremap = true}
    local silent = {noremap = true, silent = true}
    vim.api.nvim_set_keymap('n', 'n', '<Cmd>execute("normal! " . v:count1 . "n")<CR><Cmd>lua require("hlslens").start()<CR>zzzv', silent)
    vim.api.nvim_set_keymap('n', 'N', '<Cmd>execute("normal! " . v:count1 . "N")<CR><Cmd>lua require("hlslens").start()<CR>zzzv', silent)
    vim.api.nvim_set_keymap('n', '*', '*<Cmd>lua require("hlslens").start()<CR>', noremap)
    vim.api.nvim_set_keymap('n', '#', '#<Cmd>lua require("hlslens").start()<CR>', noremap)
    vim.api.nvim_set_keymap('n', 'g*', 'g*<Cmd>lua require("hlslens").start()<CR>', noremap)
    vim.api.nvim_set_keymap('n', 'g#', 'g#<Cmd>lua require("hlslens").start()<CR>', noremap)
end -- }}}

M.config = function()
  require('hlslens').setup()
end

return M

Screenshots

https://user-images.githubusercontent.com/23341710/211976768-1718dff0-346b-4613-93de-987a7c71cc15.mp4

Additional context

I haven't tried it yet with a minimal config. Maybe something is going wrong with this and live preview?

AckslD commented 1 year ago

Seems to be the case also with this minimal config:

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]
vim.g.loaded_remote_plugins = 1
local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/opt/packer.nvim'
local compile_path = package_root .. '/packer/start/packer_compiled/plugin/packer_compiled.lua'

local function load_plugins()
  vim.cmd('packadd packer.nvim')
  require('packer').startup{
    {
      {
        'wbthomason/packer.nvim',
        module = 'packer',
        cmds = {'PackerSync'},
        config = function()
        end,
      },
      {
        'kevinhwang91/nvim-hlslens',
        keys = '/',
        module = 'hlslens',
        setup = function()
          local noremap = {noremap = true}
          local silent = {noremap = true, silent = true}
          vim.api.nvim_set_keymap('n', 'n', '<Cmd>execute("normal! " . v:count1 . "n")<CR><Cmd>lua require("hlslens").start()<CR>zzzv', silent)
          vim.api.nvim_set_keymap('n', 'N', '<Cmd>execute("normal! " . v:count1 . "N")<CR><Cmd>lua require("hlslens").start()<CR>zzzv', silent)
          vim.api.nvim_set_keymap('n', '*', '*<Cmd>lua require("hlslens").start()<CR>', noremap)
          vim.api.nvim_set_keymap('n', '#', '#<Cmd>lua require("hlslens").start()<CR>', noremap)
          vim.api.nvim_set_keymap('n', 'g*', 'g*<Cmd>lua require("hlslens").start()<CR>', noremap)
          vim.api.nvim_set_keymap('n', 'g#', 'g#<Cmd>lua require("hlslens").start()<CR>', noremap)
        end,
        config = function()
          require('hlslens').setup()
        end,
      },
    },
    config = {
      auto_clean = false,
      package_root = package_root,
      compile_path = compile_path,
      display = { non_interactive = true },
    },
  }
end
_G.load_config = function()
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Cloning packer.")
  print(vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path })
  if vim.v.shell_error ~= 0 then
    print('got error, aborting')
    return
  end
else
  print("Packer already cloned.")
end
if vim.fn.filereadable(compile_path) == 0 then
  load_plugins()
  print("Sync packer")
  require('packer').sync()
  vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]
else
  load_config()
end
kevinhwang91 commented 1 year ago

Reproduced

AckslD commented 1 year ago

Thanks @kevinhwang91, unfortunately I'm still seeing the same issue.

AckslD commented 1 year ago

Can confirm that it works as expected now, thanks! :rocket:

kevinhwang91 commented 1 year ago

Great.