Wansmer / langmapper.nvim

A plugin that makes Neovim more friendly to non-English input methods 🤝
MIT License
128 stars 7 forks source link

A particular combination of plugins causes langmapper to map <Space>.. in insert mode. #20

Closed head-gardener closed 5 months ago

head-gardener commented 5 months ago

Description

Setting keymaps through iron.nvim and nvim-cmp as shown below causes langmapper to create the following mapping:

i  <Space>ьм   * <Lua 392: ~/Source/.repro/plugins/nvim-cmp/lua/cmp/utils/keymap.lua:127>
                 cmp.utils.keymap.set_map

Expected behavior

<Space>mv shouldn't be an insert mode mapping, since iron's maps are supposed to be normal and visual mode only.

init.lua

local root = vim.fn.fnamemodify("./.repro", ":p")

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

local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

local plugins = {
  'hkupty/iron.nvim',
  'hrsh7th/nvim-cmp',
  {
    'Wansmer/langmapper.nvim',
    lazy = false,
    priority = 1,
    config = function()
      require('langmapper').setup({})
    end,
    init = function()
      require('langmapper').automapping({ global = true, buffer = true })
    end
  },
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

require("iron.core").setup {
  config = {
    repl_definition = {
      sh = {
        command = { "fish" }
      },
    },
  },
  keymaps = {
    mark_visual = "<space>mv",
  },
}

local cmp = require('cmp')
local feedkey = function(key, mode)
  vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end

cmp.setup({
  mapping = {
    ['<S-Tab>'] = cmp.mapping(function()
      if cmp.visible() then
        cmp.select_prev_item()
      elseif vim.fn["vsnip#jumpable"](-1) == 1 then
        feedkey("<Plug>(vsnip-jump-prev)", "")
      end
    end, { "i", "s" })
  },
})
Wansmer commented 5 months ago

If you call require('langmapper').hack_get_keymap() after plugin setup, does bug still appear?

Seems like the same problem #15

head-gardener commented 5 months ago

@Wansmer it doesn't. Not with my full config, nor with the minimal config provided.

Wansmer commented 5 months ago

@Wansmer it doesn't. Not with my full config, nor with the minimal config provided.

You have a typo in your minimal config ('hfalsersh7th/nvim-cmp' is not a valid repo url).

Also, when add hack_get_keymap(), no imap <space> mappings are found:

-- ...
        config = function()
            require("langmapper").setup({})
            require("langmapper").hack_get_keymap()
        end,
-- ...

Before:

Screenshot 2024-02-25 at 16 36 27

After:

Screenshot 2024-02-25 at 16 36 59

Are you sure you try with hack_get_keymap()?

head-gardener commented 5 months ago

@Wansmer calling the function in config does work. I ran :lua require("langmapper").hack_get_keymap() and, as stated, got no results.

P.S. typo fixed, idk how it got there. Also, looking back this issue is on the README. Seems like my adhd got the better of me again lol.

Wansmer commented 5 months ago

Good, then I close issue as completed