Last active
January 23, 2023 02:59
-
-
Save LEI/8347b0cb997a264e94e7c39c8c11a991 to your computer and use it in GitHub Desktop.
vim.g.loaded_unimpaired == 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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