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_augroup("custom_group", {clear = true})
vim.api.nvim_create_autocmd("TermOpen", { local aucmd_dict = {
TermOpen = {
{
group = "custom_group", group = "custom_group",
pattern = "*", pattern = "*",
command = "startinsert" command = "startinsert"
}) },
{
vim.api.nvim_create_autocmd("TermOpen", {
group = "custom_group", group = "custom_group",
pattern = "*", pattern = "*",
command = "setlocal listchars= nonumber norelativenumber" command = "setlocal listchars= nonumber norelativenumber"
}) },
},
vim.api.nvim_create_autocmd("VimResized", { VimResized = {
{
group = "custom_group", group = "custom_group",
pattern = "*", pattern = "*",
command = ":wincmd =" command = ":wincmd ="
}) }
},
vim.api.nvim_create_autocmd("InsertEnter", { InsertEnter = {
{
group = "custom_group", group = "custom_group",
pattern = "*", pattern = "*",
command = "setlocal nohlsearch" command = "setlocal nohlsearch"
}) }
},
vim.api.nvim_create_autocmd("TextYankPost", { TextYankPost = {
{
group = "custom_group", group = "custom_group",
pattern = "*", pattern = "*",
callback = function () callback = function ()
require("vim.highlight").on_yank({timeout = 1000}) require("vim.highlight").on_yank({timeout = 1000})
end, end,
}) }
},
vim.api.nvim_create_autocmd("BufEnter", { BufEnter = {
{
group = "custom_group", group = "custom_group",
pattern = "*.log", pattern = "*.log",
command = ":AnsiEsc" 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