1 local M = {} |
1 local M = {} |
2 |
2 |
3 local api, fn = vim.api, vim.fn |
3 local api, fn = vim.api, vim.fn |
4 |
4 |
|
5 --- Bulk-define aliases. |
|
6 ---@param aliases table<string, string> |
5 function M.calias(aliases) |
7 function M.calias(aliases) |
6 for abbrev, expand in pairs(aliases) do |
8 for abbrev, expand in pairs(aliases) do |
7 vim.cmd.cnoreabbrev( |
9 vim.cmd.cnoreabbrev( |
8 string.format( |
10 string.format( |
9 [[<expr> %s (getcmdtype() == ":" && getcmdline() == "%s") ? "%s" : "%s"]], |
11 [[<expr> %s (getcmdtype() == ":" && getcmdline() == "%s") ? "%s" : "%s"]], |
14 ) |
16 ) |
15 ) |
17 ) |
16 end |
18 end |
17 end |
19 end |
18 |
20 |
|
21 --- Shortcut for autocmd creation. |
|
22 --- @param group string | number |
|
23 --- @param event string | string[] |
|
24 --- @param pattern string | string[] |
|
25 --- @param opts table | string | fun(ctx) `nvim_create_autocmd` options OR a function for the `callback` option OR a string for the command option |
19 function M.autocmd(group, event, pattern, opts) |
26 function M.autocmd(group, event, pattern, opts) |
20 if type(opts) == "function" then |
27 if type(opts) == "function" then |
21 local func = opts |
28 opts = { callback = opts } |
22 opts = { |
29 elseif type(opts) == "string" then |
23 callback = function(_) |
30 opts = { command = opts } |
24 func() |
|
25 end, |
|
26 } |
|
27 end |
31 end |
28 |
32 |
29 api.nvim_create_autocmd( |
33 api.nvim_create_autocmd( |
30 event, |
34 event, |
31 vim.tbl_extend("keep", opts, { |
35 vim.tbl_extend("keep", opts, { |