nvim: autocmd: Use the new auto command API

This commit is contained in:
Sanchayan Maity 2022-03-02 09:05:35 +05:30
parent 7503e1a4f2
commit ca7172b14a
1 changed files with 36 additions and 33 deletions

View File

@ -1,36 +1,39 @@
local vim = vim
local api = vim.api
vim.api.nvim_create_augroup("custom_group", {clear = true})
--- This function is taken from https://github.com/norcalli/nvim_utils
local function nvim_create_augroups(definitions)
for group_name, definition in pairs(definitions) do
api.nvim_command('augroup '..group_name)
api.nvim_command('autocmd!')
for _, def in ipairs(definition) do
local command = table.concat(vim.tbl_flatten{'autocmd', def}, ' ')
api.nvim_command(command)
end
api.nvim_command('augroup END')
end
end
vim.api.nvim_create_autocmd("TermOpen", {
group = "custom_group",
pattern = "*",
command = "startinsert"
})
local autocmds = {
terminal_job = {
{ "TermOpen", "*", "startinsert" };
{ "TermOpen", "*", "setlocal listchars= nonumber norelativenumber" };
};
resize_windows_proportionally = {
{ "VimResized", "*", ":wincmd =" };
};
toggle_search_highlighting = {
{ "InsertEnter", "*", "setlocal nohlsearch" };
};
lua_highlight = {
{ "TextYankPost", "*", "silent! lua vim.highlight.on_yank({timeout=1000})" };
};
ansi_esc_log = {
{ "BufEnter", "*.log", ":AnsiEsc" };
};
}
vim.api.nvim_create_autocmd("TermOpen", {
group = "custom_group",
pattern = "*",
command = "setlocal listchars= nonumber norelativenumber"
})
nvim_create_augroups(autocmds)
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"
})