gbprod / cutlass.nvim

Plugin that adds a 'cut' operation separate from 'delete'
Do What The F*ck You Want To Public License
192 stars 5 forks source link

Does not work with which-key.nvim #20

Open kevintraver opened 1 year ago

kevintraver commented 1 year ago

When using cutlass with which-key, the remapped keys prevent which-key from opening the popup.

gbprod commented 1 year ago

Hey! Thanks for opening this issue I'm currently on vacation, I will check this when I come back 😉

gbprod commented 1 year ago

I think it's more of a limitation on the which-key side. As which-key comes with presets for default vim keys, it considers that there is a conflict. When running :checkhealth which-key, I have this :

- WARNING conflicting keymap exists for mode **"n"**, lhs: **"d"**
- rhs: `"_d`
- WARNING conflicting keymap exists for mode **"n"**, lhs: **"c"**
- rhs: `"_c`
....

It seems legit but I've tried to disable which-key presets like this :

local which_key = require("which-key")

which_key.setup({
  plugins = {
    presets = {
      operators = false,
      motions = false,
    },
  },
})

Or like this :

local which_key = require("which-key")
local presets = require("which-key.plugins.presets")
presets.operators["d"] = nil
which_key.setup({})

but it does not works....

Maybe @folke can help us on that ? Maybe we should open an issue on which-key repo ?

sebastianst commented 1 year ago

Related to this, for me cutlass doesn't work at all if the which-key plugin is also enabled. The pop-ups of which-key show up, but the d and s bindings are just not set by cutlass. Seems like an ordering issue to me.

sebastianst commented 1 year ago

@gbprod I think I fixed it by adding

  {
    "folke/which-key.nvim",
    opts = function(_, opts)
        opts.triggers_blacklist = {
            -- list of mode / prefixes that should never be hooked by WhichKey
            -- this is mostly relevant for keymaps that start with a native binding
            i = { "j", "k", "d", "D", "s", "S" },
            v = { "j", "k", "d", "D", "s", "S" },
            n = { "d", "D", "s", "S" },
        }
        return opts
    end,
  },

to .config/nvim/lua/user/core.lua (or any other lua file in that dir), which adds the keys that cutlass remaps to which-key's blacklist. Note that I use AstroNvim in this setup. The key here is to expand the triggers_blacklist option of which-key.

It would be nice if cutlass could be made which-key aware. If it detects which-key, it could configure the triggers_blacklist of which-key, and additionally add descriptions for the new bindings to which-key.

b0ae989c commented 9 months ago

Assuming we use lazy.nvim to manage plugins, a workaround for this issue is to set lazy = false for cutlass.

gbprod commented 9 months ago

I've just tried that but it doesn't works for me. I have which-key menu that appear, but cutlass mappings are not set :/

Maybe you have a more complete config to share @b0ae989c ?

b0ae989c commented 9 months ago

@gbprod Here is a minimal init.lua. Run with nvim -u init.lua with Neovim v0.9.4 on macOS, and cutlass.nvim works as expected.

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',
    'https://github.com/folke/lazy.nvim.git',
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)
local plugins = {
  'folke/tokyonight.nvim',
  {
    'folke/which-key.nvim',
    event = 'VeryLazy',
  },
  {
    'gbprod/cutlass.nvim',
    lazy = false,
    config = true,
  },
}
require('lazy').setup(plugins, { root = root .. '/plugins' })
vim.cmd.colorscheme('tokyonight')
z775729168 commented 9 months ago

@b0ae989c It works, but which-key can't show the menu in visual mode. If the key map is something like <leader>a, and it has a submenu, everything is fine, only the <leader> menu won't pop. And it needs to be pressed fast enough, <leader> will become a normal space .

b0ae989c commented 9 months ago

<leader> will become a normal space

That's a separate issue. With the config above, <Leader> is the default key \.

z775729168 commented 9 months ago

@b0ae989c

When using cutlass with which-key, the remapped keys prevent which-key from opening the popup.

I do not know why, but the plugin actually remaps s<space>. https://github.com/gbprod/cutlass.nvim/blob/708864fb2263226aabceaf5b2c2eee9841132668/lua/cutlass.lua#L74-L76

Add s<space> to config.exclude fix it.

z775729168 commented 9 months ago

I am sorry, it seems I misunderstood something... I tested the triggers_blacklist and layz=false, none of them worked with me.

Mini.operator has the same symptoms.