Skip to content

Instantly share code, notes, and snippets.

@LEI
Last active January 23, 2023 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LEI/8347b0cb997a264e94e7c39c8c11a991 to your computer and use it in GitHub Desktop.
Save LEI/8347b0cb997a264e94e7c39c8c11a991 to your computer and use it in GitHub Desktop.
vim.g.loaded_unimpaired == 1
-- Copy mappings prefixed with [ and ] to ( and ) and add desc
for _, mode in ipairs({ 'n', 'o', 'x' }) do
local keymaps = vim.api.nvim_get_keymap(mode)
for _, keymap in ipairs(keymaps) do
for left, right in pairs({ ['('] = '[', [')'] = ']' }) do
if keymap.lhs ~= right and keymap.lhs:match('^%' .. right) then
local lhs = keymap.lhs:gsub('^%' .. right, left)
local rhs = keymap.lhs
local callback = keymap.callback
local desc = keymap.desc and keymap.desc
or keymap.rhs and keymap.rhs:gsub('^<%w+>%(([%w-]+)%)', '%1'):gsub('-', ' '):gsub('^unimpaired ', '')
or rhs
vim.api.nvim_set_keymap(mode, lhs, rhs, { callback = callback, desc = desc })
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment