2023-12-21 16:21:14 +01:00
|
|
|
-- TODO: operator for wrapping motion with fold
|
2023-01-10 02:38:06 +01:00
|
|
|
local M = {}
|
|
|
|
|
|
|
|
-- {{{ Helpers
|
|
|
|
---Performs a basic move operation
|
|
|
|
---Moves a keybind to a different set of keys.
|
|
|
|
---Useful for moving built in keybinds out of the way.
|
|
|
|
---@param from string
|
|
|
|
---@param to string
|
|
|
|
---@param opts table|nil
|
|
|
|
function M.move(from, to, opts)
|
|
|
|
vim.keymap.set("n", to, from, opts)
|
|
|
|
vim.keymap.set("n", from, "<Nop>")
|
|
|
|
end
|
|
|
|
|
|
|
|
---Create a textobject defined by some delimiters
|
|
|
|
---@param from string
|
|
|
|
---@param to string
|
|
|
|
---@param name string
|
2023-12-21 16:21:14 +01:00
|
|
|
---@param opts table|nil
|
|
|
|
function M.delimitedTextobject(from, to, name, opts)
|
|
|
|
opts = opts or {}
|
|
|
|
|
|
|
|
if opts.desc == nil then
|
|
|
|
opts.desc = name
|
|
|
|
end
|
2023-01-10 02:38:06 +01:00
|
|
|
|
|
|
|
vim.keymap.set({ "v", "o" }, "i" .. from, "i" .. to, opts)
|
|
|
|
vim.keymap.set({ "v", "o" }, "a" .. from, "a" .. to, opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
---Helper to create a normal mode mapping and give it some description.
|
|
|
|
---@param from string
|
|
|
|
---@param to string|function
|
|
|
|
---@param desc string
|
|
|
|
---@param silent boolean|nil
|
2023-04-17 15:19:41 +02:00
|
|
|
---@param isLocal boolean|nil
|
|
|
|
function M.nmap(from, to, desc, silent, isLocal)
|
2023-01-10 02:38:06 +01:00
|
|
|
if silent == nil then
|
|
|
|
silent = true
|
|
|
|
end
|
2023-04-17 15:19:41 +02:00
|
|
|
|
|
|
|
if isLocal == nil then
|
|
|
|
isLocal = false
|
|
|
|
end
|
|
|
|
|
2023-08-14 13:49:55 +02:00
|
|
|
vim.keymap.set(
|
|
|
|
"n",
|
|
|
|
from,
|
|
|
|
to,
|
|
|
|
{ desc = desc, silent = silent, buffer = isLocal }
|
|
|
|
)
|
2023-01-10 02:38:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
function M.setup()
|
|
|
|
-- {{{ Text objects
|
|
|
|
M.delimitedTextobject("q", '"', "[q]uotes")
|
|
|
|
M.delimitedTextobject("a", "'", "[a]postrophes")
|
|
|
|
M.delimitedTextobject("r", "[", "squa[r]e brackets")
|
|
|
|
-- }}}
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|