63 lines
1.7 KiB
Lua
63 lines
1.7 KiB
Lua
local M = {}
|
|
|
|
--- vim.notify title
|
|
M.appid = "Nvim Config"
|
|
|
|
--- extend vim.kemap.set
|
|
---@param mode string|table mode for the keymap
|
|
---@param bind string keymap
|
|
---@param cmd function|string command to run
|
|
---@param opts vim.keymap.set.Opts? keymap options
|
|
function M.map(mode, bind, cmd, opts)
|
|
opts = opts or {}
|
|
opts["noremap"] = true
|
|
opts["silent"] = true
|
|
|
|
-- attempt to autogenerate a basic description
|
|
if not opts["desc"] then
|
|
if type(cmd) == "string" then
|
|
opts["desc"] = cmd:gsub("<%a+>", "")
|
|
elseif type(cmd) == "function" then
|
|
-- TODO: find a way to generate a better name
|
|
local file_name = vim.fn.fnamemodify(debug.getinfo(cmd, "S").short_src, ":t")
|
|
opts["desc"] = "origin@"..file_name
|
|
end
|
|
end
|
|
|
|
vim.keymap.set(mode, bind, cmd, opts)
|
|
end
|
|
|
|
--- a small map wrapper to easily create local buffer mappings
|
|
---@param mode string|table mode for the keymap
|
|
---@param bind string keymap
|
|
---@param cmd function|string command to run
|
|
---@param opts table? keymap options
|
|
function M.map_local(mode, bind, cmd, opts)
|
|
opts = opts or {}
|
|
opts["buffer"] = 0
|
|
M.map(mode, bind, cmd, opts)
|
|
end
|
|
|
|
--- shorten vim.api.nvim_create_autocmd call
|
|
M.auto = vim.api.nvim_create_autocmd
|
|
|
|
--- extend auto group
|
|
---@param name string name of the autogroup
|
|
---@param opts table? table of options
|
|
---@return integer
|
|
function M.augroup(name, opts)
|
|
opts = opts or {}
|
|
return vim.api.nvim_create_augroup(name, opts)
|
|
end
|
|
|
|
--- Make an action lazy. This is mostly useful for keybinds which do a lot and
|
|
--- you want to make sure the screen doesn't flash
|
|
---@param txt string the action
|
|
---@return string lazified
|
|
---@nodiscard
|
|
function M.lz(txt)
|
|
return "<cmd>se lz<CR>"..txt.."<cmd>se lz!<CR>"
|
|
end
|
|
|
|
return M
|