nvim: autocmd: Refactor the way we call auto command API

This commit is contained in:
Sanchayan Maity 2022-03-06 17:48:50 +05:30
parent 28049ed540
commit 39f9628197

View file

@ -1,39 +1,52 @@
vim.api.nvim_create_augroup("custom_group", {clear = true})
vim.api.nvim_create_autocmd("TermOpen", {
group = "custom_group",
pattern = "*",
command = "startinsert"
})
local aucmd_dict = {
TermOpen = {
{
group = "custom_group",
pattern = "*",
command = "startinsert"
},
{
group = "custom_group",
pattern = "*",
command = "setlocal listchars= nonumber norelativenumber"
},
},
VimResized = {
{
group = "custom_group",
pattern = "*",
command = ":wincmd ="
}
},
InsertEnter = {
{
group = "custom_group",
pattern = "*",
command = "setlocal nohlsearch"
}
},
TextYankPost = {
{
group = "custom_group",
pattern = "*",
callback = function ()
require("vim.highlight").on_yank({timeout = 1000})
end,
}
},
BufEnter = {
{
group = "custom_group",
pattern = "*.log",
command = ":AnsiEsc"
}
}
}
vim.api.nvim_create_autocmd("TermOpen", {
group = "custom_group",
pattern = "*",
command = "setlocal listchars= nonumber norelativenumber"
})
vim.api.nvim_create_autocmd("VimResized", {
group = "custom_group",
pattern = "*",
command = ":wincmd ="
})
vim.api.nvim_create_autocmd("InsertEnter", {
group = "custom_group",
pattern = "*",
command = "setlocal nohlsearch"
})
vim.api.nvim_create_autocmd("TextYankPost", {
group = "custom_group",
pattern = "*",
callback = function ()
require("vim.highlight").on_yank({timeout = 1000})
end,
})
vim.api.nvim_create_autocmd("BufEnter", {
group = "custom_group",
pattern = "*.log",
command = ":AnsiEsc"
})
for event, opt_tbls in pairs(aucmd_dict) do
for _, opt_tbl in pairs(opt_tbls) do
vim.api.nvim_create_autocmd(event, opt_tbl)
end
end