unblevable / quick-scope

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

First call to quick_scope#Reload fails when <C-c> is remapped using vim.keymap.set and a lua function in NeoVim #88

Closed mrcjkb closed 1 year ago

mrcjkb commented 2 years ago

I have <C-c> remapped to call a lua function using vim.keymap.set.

It appears that the quick_scope#Reload() function can't handle this, and errors when attempting to restore b:qs_prev_ctrl_c_map.

Here is a minimal neovim config to reproduce the behaviour:

Expected behaviour:

Actual behaviour:

-- init.lua

-- Ignore default config
local fn = vim.fn
local config_path = fn.stdpath('config') 
vim.opt.runtimepath:remove(config_path)

-- Ignore default plugins
local data_path = fn.stdpath('data')
local pack_path = data_path .. '/site'
vim.opt.packpath:remove(pack_path)

-- append temporary config and pack dir
local test_dir = '/tmp/nvim-minimal'
vim.opt.runtimepath:append(test_dir)
vim.opt.packpath:append(test_dir)

-- bootstrap packer
local install_path = test_dir .. '/pack/packer/start/packer.nvim'
local install_plugins = false

if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
  vim.cmd('!git clone https://github.com/wbthomason/packer.nvim ' .. install_path)
  vim.cmd('packadd packer.nvim')
  install_plugins = true
end

local packer = require('packer') 

packer.init({
  package_root = test_dir .. '/pack',
  compile_path = test_dir .. '/plugin/packer_compiled.lua'
})

-- Toggle the quickfix list (only opens if it is populated)
vim.keymap.set('n', '<C-c>', function()
  print("<C-c> has been remapped.")
end)

packer.startup(function(use)
  use 'wbthomason/packer.nvim'

  use {
    'unblevable/quick-scope',
    setup = function()
      vim.g.qs_highlight_on_keys = {'f', 'F', 't', 'T'}
    end
  }

  if install_plugins then
    packer.sync()
  end
end)

I guess a fix would be not to temporarily remap <C-c> if it cannot be interpreted by vimscript?

mrcjkb commented 2 years ago

This is low priority for me, because I was able to work around this issue by wrapping the lua function in a file:

-- ~/.config/nvim/lua/kaymap-utils.lua
local M = {}
M.test_func = function()
  print('<C-c> has been remapped.')
end

and setting the keymap like this:

vim.keymap.set('n', '<C-c>', '<cmd>lua require("keymap-utils").test_func()<CR>')

A bit ugly, but it works.

mrcjkb commented 1 year ago

Looks like this has been fixed in NeoVim 0.8.