2022-03-09 19:03:04 +01:00
|
|
|
local helpers = require("my.helpers")
|
|
|
|
local arpeggio = vim.fn["arpeggio#map"]
|
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
2022-12-27 14:02:03 +01:00
|
|
|
---Create an arpeggio mapping
|
|
|
|
---@param mode string
|
|
|
|
---@param lhs string
|
|
|
|
---@param rhs string
|
|
|
|
---@param opts table|nil
|
|
|
|
local function chord(mode, lhs, rhs, opts)
|
2022-09-12 13:50:02 +02:00
|
|
|
if string.len(mode) > 1 then
|
|
|
|
for i = 1, #mode do
|
|
|
|
local c = mode:sub(i, i)
|
2022-12-27 14:02:03 +01:00
|
|
|
chord(c, lhs, rhs, opts)
|
2022-09-12 13:50:02 +02:00
|
|
|
end
|
|
|
|
else
|
2022-10-09 03:28:51 +02:00
|
|
|
local options = helpers.mergeTables(opts or {}, { noremap = true })
|
2022-09-12 13:50:02 +02:00
|
|
|
local settings = options.settings or ""
|
2022-03-09 19:03:04 +01:00
|
|
|
|
2022-12-27 14:02:03 +01:00
|
|
|
if options.silent then
|
|
|
|
settings = settings .. "s"
|
|
|
|
end
|
2022-03-09 19:03:04 +01:00
|
|
|
|
2022-10-09 03:28:51 +02:00
|
|
|
arpeggio(mode, settings, not options.noremap, lhs, rhs)
|
2022-09-12 13:50:02 +02:00
|
|
|
end
|
2022-03-09 19:03:04 +01:00
|
|
|
end
|
|
|
|
|
2022-12-27 14:02:03 +01:00
|
|
|
---Create a silent arpeggio mapping
|
|
|
|
---@param mode string
|
|
|
|
---@param lhs string
|
|
|
|
---@param rhs string
|
|
|
|
---@param opts table|nil
|
|
|
|
local function chordSilent(mode, lhs, rhs, opts)
|
2022-10-09 03:28:51 +02:00
|
|
|
local options = helpers.mergeTables(opts or {}, { silent = true })
|
2022-12-27 14:02:03 +01:00
|
|
|
chord(mode, lhs, rhs, options)
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.setup()
|
|
|
|
chordSilent("n", "ji", ":silent :write<cr>") -- Saving
|
|
|
|
chord("i", "jk", "<Esc>") -- Remap Esc to jk
|
|
|
|
chord("nv", "cp", '"+') -- Press cp to use the global clipboard
|
2022-03-09 19:03:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|