unblevable / quick-scope

Lightning fast left-right movement in Vim
MIT License
1.42k stars 54 forks source link

Plugin doesn't handle mapping dicts in Neovim correctly #93

Closed gregorias closed 1 year ago

gregorias commented 1 year ago

Problem

The plugin crashes when recovering a Lua-callback map in Neovim.

Reproduction

Run Neovim with the following config:

-- .config/nvim/init.lua
-- | Fetches Lazy if not present.
function bootstrap_lazy()
  local lazypath = vim.fn.stdpath('data')..'/lazy/lazy.nvim'
  if not vim.loop.fs_stat(lazypath) then
    vim.fn.system{
      'git', 'clone',
      '--filter=blob:none',
      'https://github.com/folke/lazy.nvim.git',
      '--branch=stable',
      lazypath,
    }
  end
  vim.opt.rtp:prepend(lazypath)
end
bootstrap_lazy()
require'lazy'.setup({
  { 'unblevable/quick-scope',
    init = function()
      -- Trigger a highlight in the appropriate direction when pressing these keys:
      vim.g.qs_highlight_on_keys = { 'f', 'F', 't', 'T' }
    end,
  },

  { 'greymd/oscyank.vim',
    keys = '<C-c>',
  },
  }
)

Open Neovim

nvim .config/nvim/init.lua

Press fc (to jump to c).

You'll see the following error:

Error detected while processing function quick_scope#Reload[6]..quick_scope#mapping#Restore:
line   13:
E716: Key not present in Dictionary: "rhs, '|'), '<SID>', '<SNR>' . a:mapping.sid . '_', 'g')"
E116: Invalid arguments for function escape
E116: Invalid arguments for function substitute

Solution

The problem stems from the fact that Neovim may have a Lua callback instead of rhs (https://github.com/neovim/neovim/issues/22399):

{'lnum': 0, 'script': 0, 'replace_keycodes': 1, 'silent': 0, 'callback': function('<lambda>1'), 'noremap': 1, 'lhs': '<C-C>', 'mode': 'n', 'lhsraw': '<80><fc>^DC', 'nowait': 0, 'expr': 1, 'sid': -8, 'buffer': 0, 'lhsrawalt':
 '^C'}

I suggest this plugin uses mapset instead of its custom restore function.