nixvim icon indicating copy to clipboard operation
nixvim copied to clipboard

modules/keymaps: add "buffer" option to mapConfigOptions

Open iSma opened this issue 1 year ago • 7 comments

This allows to define buffer-local keymaps, which is specially useful when combined with keymapsOnEvents.

iSma avatar May 25 '24 21:05 iSma

Is this supposed to work ? :h nvim_set_keymap states that Optional parameters map: Accepts all |:map-arguments| as keys except <buffer>, values are booleans (default false).

GaetanLepage avatar May 25 '24 21:05 GaetanLepage

And To set a buffer-local mapping, use |nvim_buf_set_keymap()|.

GaetanLepage avatar May 25 '24 21:05 GaetanLepage

I tested the change with vim.keymap.set, where :h vim.keymap.set() states:

Also accepts:
• {buffer}? (`integer|boolean`) Creates buffer-local mapping,
  `0` or `true` for current buffer.

A quick grep through the repo found no usages of nvim_set_keymap, only vim.keymap.set, but I could have missed something.

(I've thought about typing the option either bool int, but I don't see a use-case where setting a specific buffer number would be useful.)

iSma avatar May 25 '24 22:05 iSma

A quick grep through the repo found no usages of nvim_set_keymap, only vim.keymap.set, but I could have missed something.

Oh, yes, you are completely right. I had forgotten about this. We used to use nvim_set_keymap.

(I've thought about typing the option either bool int, but I don't see a use-case where setting a specific buffer number would be useful.)

True, I don't see whether that would be useful... Any opinion @traxys @MattSturgeon ?

GaetanLepage avatar May 25 '24 22:05 GaetanLepage

I've thought about typing the option either bool int, but I don't see a use-case where setting a specific buffer number would be useful.

I assume they accept int for backwards compatibility reasons? Or do they allow specifying which buffer to create the mapping in using a buffnr?

I personally don't see the use-case, but it'd be better to match upstream typing if there's actual functionality there. Otherwise I agree, keep it simple.

MattSturgeon avatar May 25 '24 22:05 MattSturgeon

I assume they accept int for backwards compatibility reasons? Or do they allow specifying which buffer to create the mapping in using a buffnr?

For me it is the latter, i.e. to give a buffer id.

I personally don't see the use-case, but it'd be better to match upstream typing if there's actual functionality there. Otherwise I agree, keep it simple.

Although it makes no sense to me to set a binding for buffer x at nix build time, I don't mind if we type it the same way as upstream. Maybe @traxys will have a stronger opinion on that.

GaetanLepage avatar May 27 '24 14:05 GaetanLepage

I'd rather not expose the "int", people would be able to access it using rawLua, and it does not make sense in nixvim I think

traxys avatar May 27 '24 16:05 traxys