nvimdev/dope

Support binding multiple keys to the same target in the one configuration item

0x5459 opened this issue · 2 comments

Example:

imap({
  -- { 'jk', '<ESC>', opts(noremap, 'Goto Normal mode') },
  -- { 'kj', '<ESC>', opts(noremap, 'Goto Normal mode') },
  -- { 'jj', '<ESC>', opts(noremap, 'Goto Normal mode') },
  { { 'jk', 'kj', 'jj' }, '<ESC>', opts(noremap, 'Goto Normal mode') },
  -- ...
})

xmap({
  -- { 'J', ":move '>+1<CR>gv-gv", opts(noremap, 'Move current line/block up in visual mode')) },
  -- { '<A-j>', ":move '>+1<CR>gv-gv", opts(noremap, 'Move current line/block up in visual mode')) },
  -- { 'K', ":move '<-2<CR>gv-gv", opts(noremap, 'Move current line/block down in visual mode')) },
  -- { '<A-k>', ":move '<-2<CR>gv-gv", opts(noremap, 'Move current line/block down in visual mode')) },
  { { 'J', '<A-j>' }, ":move '>+1<CR>gv-gv", opts(noremap, 'Move current line/block up in visual mode')) },
  { { 'K', '<A-k>' }, ":move '<-2<CR>gv-gv", opts(noremap, 'Move current line/block down in visual mode')) },
  -- ...
})

This way will be convenient, If you think it's ok, I'm happy to start a PR for this.

I think it's ok. does there has any other designs about this?

I think it's ok. does there has any other designs about this?

Add a function like this? Sorry i'm new-player to vim and lua.

-- lua/core/keymap.lua

local function set(mode, lhs, rhs, opts)
  if type(lhs) ~= 'table' then
    set(mode, { lhs }, rhs, opts)
    return
  end
  for _, k in ipairs(lhs) do
    vim.keymap.set(mode, k, rhs, opts)
  end
end

or

-- lua/core/keymap.lua

local function set(mode, lhs, rhs, opts)
  if type(lhs) == 'table' then
    for _, k in ipairs(lhs) do
      vim.keymap.set(mode, k, rhs, opts)
    end
  else
    vim.keymap.set(mode, lhs, rhs, opts)
  end
end