hop.nvim icon indicating copy to clipboard operation
hop.nvim copied to clipboard

Getting a 'Column value outside range' when using HopChar1 on a soft wrapped line

Open brneor opened this issue 6 months ago • 0 comments

Describe the bug When I try to use the remaps to t on a line that is soft wrapped I get an error:

E5108: Error executing lua: /root/.local/share/nvim/lazy/hop.nvim/lua/hop/init.lua:239: Column value outside
 range
stack traceback:
        [C]: in function 'nvim_win_set_cursor'
        /root/.local/share/nvim/lazy/hop.nvim/lua/hop/init.lua:239: in function 'move_cursor_to'
        /root/.local/share/nvim/lazy/hop.nvim/lua/hop/init.lua:259: in function 'callback'
        /root/.local/share/nvim/lazy/hop.nvim/lua/hop/init.lua:363: in function 'refine_hints'
        /root/.local/share/nvim/lazy/hop.nvim/lua/hop/init.lua:327: in function 'hint_with_callback'
        /root/.local/share/nvim/lazy/hop.nvim/lua/hop/init.lua:258: in function 'hint_with_regex'
        /root/.local/share/nvim/lazy/hop.nvim/lua/hop/init.lua:447: in function 'hint_char1'
        /root/.config/nvim/lua/plugins/hop.lua:51: in function </root/.config/nvim/lua/plugins/hop.lua:50>

To Reproduce

  1. Install hop.nvim
  2. Map t to <cmd>:lua require'hop'.hint_char1({direction = require'hop.hint'.HintDirection.AFTER_CURSOR,current_line_only = true, hint_offset = -1})<cr>
  3. Open any file that has a long line
  4. set wrap
  5. Go to the start of the long line, type t, a character that's on the wrapped part of the line and then the hop hint letter.
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "runtime", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  -- stylua: ignore
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath })
end
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)

-- install plugins
local plugins = {
  { "AstroNvim/AstroNvim", import = "astronvim.plugins" },

  {
    "smoka7/hop.nvim",
    version = "*",
    event = "BufRead",
    config = function()
      require("hop").setup({
        keys = "tnplvmdhsefucwyxriao",
        multi_windows = false,
      })
      vim.api.nvim_set_keymap("", "s", "<cmd>HopWord<cr>", { silent = true })
      vim.api.nvim_set_keymap("", "h", "<cmd>HopChar2<cr>", { silent = true })
      vim.api.nvim_set_keymap("", "L", "<cmd>HopLine<cr>", { silent = true })
      vim.api.nvim_set_keymap("", "l", "<cmd>HopLineStart<cr>", { silent = true })
      vim.api.nvim_set_keymap("", "<C-w>", "<cmd>HopWordCurrentLineAC<cr>", { silent = true })
      vim.api.nvim_set_keymap("", "<C-b>", "<cmd>HopWordCurrentLineBC<cr>", { silent = true })
      vim.api.nvim_set_keymap(
        "",
        "f",
        "<cmd>:lua require'hop'.hint_char1({direction = require'hop.hint'.HintDirection.AFTER_CURSOR,current_line_only = true})<cr>",
        { silent = true }
      )
      vim.api.nvim_set_keymap(
        "",
        "F",
        "<cmd>:lua require'hop'.hint_char1({direction = require'hop.hint'.HintDirection.BEFORE_CURSOR,current_line_only = true})<cr>",
        { silent = true }
      )
      vim.api.nvim_set_keymap(
        "",
        "t",
        "<cmd>:lua require'hop'.hint_char1({direction = require'hop.hint'.HintDirection.AFTER_CURSOR,current_line_only = true,hint_offset = -1})<cr>",
        { silent = true }
      )
      vim.api.nvim_set_keymap(
        "",
        "T",
        "<cmd>:lua require'hop'.hint_char1({direction = require'hop.hint'.HintDirection.BEFORE_CURSOR,current_line_only = true,hint_offset = 1})<cr>",
        { silent = true }
      )
    end,
  },
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

-- add anything else here (autocommands, vim.filetype, etc.)

Expected behavior Cursor should jump to chosen character.

Screenshots

https://github.com/user-attachments/assets/69d72bb7-5e00-4a7f-8334-27d9c2579387

version (please complete the following information):

  • Nvim version: v0.10.1
  • hop.nvim version: v2.7.1

Additional context Without setting the hint_offset the issue does not occurs. Also, I initially thought that was a AstroNvim issue and reported here. There's some insight from the dev there.

brneor avatar Aug 27 '24 20:08 brneor