Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"mode" can't be used in group mappings #56

Closed
cideM opened this issue May 5, 2021 · 12 comments
Closed

"mode" can't be used in group mappings #56

cideM opened this issue May 5, 2021 · 12 comments

Comments

@cideM
Copy link

cideM commented May 5, 2021

If I try to do something like this

wk.register {
    ["<leader>f"] = {
        name = "+find",
        o = {"<Plug>(GrepperOperator)", "operator"},
        o = {"<Plug>(GrepperOperator)", "operator", mode="x"},
    },
}

the plugin complains with

Error detected while processing VimEnter Autocommands for "*":
E5108: Error executing lua .../home-manager/start/which-key-niv/lua/which-key/keys.lua:159: Invalid key mapping: { "<Plug>(GrepperOperator)"
, "operator",
  mode = "x"
}

so I need to pull the mappings apart:

wk.register({
    ["<leader>f"] = {
        o = {"<Plug>(GrepperOperator)", "operator"},
    }},{mode="x"}
)
wk.register {
    ["<leader>f"] = {
        name = "+find",
        o = {"<Plug>(GrepperOperator)", "operator"},
    },
}

which works but is a bit annoying because now there are always multiple places where I need to look for the mappings for a given group. Would you consider making mode available in group mappings too? Because things like silent and noremap work.

@folke
Copy link
Owner

folke commented May 5, 2021

Just added this. Adding mode='x' as in your example, now works as expected

@cideM
Copy link
Author

cideM commented May 5, 2021

Awesome, it did fix that issue. But I have another issue with regards to modes. I can create a new issue if you'd prefer that. I'm trying to translate

nmap gs  <plug>(GrepperOperator)
xmap gs  <plug>(GrepperOperator)

but the following config is obviously stupid because I'm just overwriting a key in a table

["<leader>f"] = {
  name = "+Find",
  o = {"<Plug>(GrepperOperator)", "string"},
  o = {"<Plug>(GrepperOperator)", "string", mode="x"},
}

results in <leader>fo only being shown in visual selection (great!) but not in normal mode (sad panda). I assume the second o overrides the first, since it doesn't account for the possibility of duplicates which are OK because they're in different modes?

EDIT: strike through to banish this rather embarassing brain freeze

@folke
Copy link
Owner

folke commented May 5, 2021

That's actually a lua table where you assign the index o twice.

So I never know there were actually two entries there.

@folke
Copy link
Owner

folke commented May 5, 2021

I'll make a change where you can set mode = {'n', 'x'}

@cideM
Copy link
Author

cideM commented May 5, 2021

That's actually a lua table where you assign the index o twice.

So I never know there were actually two entries there.

🤦 thanks

@folke
Copy link
Owner

folke commented May 11, 2021

I'll close this and leave it as it is right now. There's multiple possibilities to define the maps for multiple modes.

@folke folke closed this as completed May 11, 2021
@kdheepak
Copy link

kdheepak commented Jul 1, 2021

I was expecting this to work but it doesn't.

local mappings = {
    p = {'"+p', 'Paste from clipboard', mode = {'n', 'v'}},
    P = {'"+P', 'Paste from clipboard (before)', mode = {'n', 'v'}},
    y = {'"+y', 'Yank to clipboard', mode = {'n', 'v'}},
    Y = {'"+Y', 'Yank line to clipboard', mode = {'n', 'v'}},
}

local opts = {
    mode = "n", 
    prefix = "<leader>",
}

wk.register(mappings, opts)

Is the only way to do this define opts twice, one with mode = "n" and another with mode = "v"?

@kdheepak
Copy link

kdheepak commented Jul 1, 2021

The error that I get when I try the above is this:

"lua/kdheepak/which-key.lua" 168L, 8385C
Error detected while processing VimEnter Autocommands for "*":
E5108: Error executing lua .../pack/packer/start/which-key.nvim/lua/which-key/keys.lua:251: Error executing lua: Vim:E730: using List as a String
Press ENTER or type command to continue

@AmeerTaweel
Copy link

I'll make a change where you can set mode = {'n', 'x'}

@folke any updates on this? I tried using it today, but it did not work. This is the code I tried to use:

which_key.register({
	d = { [["+d]], "delete to clipboard" },
	p = { [["+p]], "paste from clipboard" },
	P = { [["+P]], "paste from clipboard" },
	y = { [["+y]], "yank to clipboard" }
}, { prefix = "<leader>", mode = { "n", "x" } })

@hermitmaster
Copy link

I'll make a change where you can set mode = {'n', 'x'}

@folke any updates on this? I tried using it today, but it did not work. This is the code I tried to use:

which_key.register({
	d = { [["+d]], "delete to clipboard" },
	p = { [["+p]], "paste from clipboard" },
	P = { [["+P]], "paste from clipboard" },
	y = { [["+y]], "yank to clipboard" }
}, { prefix = "<leader>", mode = { "n", "x" } })

I just ran into the same issue trying to map text objects.
['ih'] = { ':<C-U>Gitsigns select_hunk<cr>', 'Select Hunk', mode = { 'o', 'x' } },

@LukasDoesDev
Copy link

image
Is it possible to make this work?

@afreakk
Copy link

afreakk commented Jan 21, 2023

image Is it possible to make this work?

You can do it like:

    s = { "bind1", "blabla" },
    ["ss"] = { "bind2", "blabla" },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants