Neovim: autocmd

An autocommand is a command that is executed automatically in response to some event, such as a file being read or written or a buffer change (documentation).

Start git commit messages in insert mode

vim.api.nvim_create_augroup("bufcheck", { clear = true })
vim.api.nvim_create_autocmd("FileType", {
    group = "bufcheck",
    pattern = { "gitcommit", "gitrebase" },
    command = "startinsert | 1",
})

Enable spell checker on certain files

vim.api.nvim_create_autocmd(
    { "BufRead", "BufNewFile" },
    { pattern = { "*.txt", "*.md", "*.tex" }, command = "setlocal spell" }
)

Set timer to write all buffers every second

local function write_buf_timer()
    vim.fn.timer_start(1000, function()
        vim.api.nvim_command('wall')
    end)
end

vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = write_buf_timer })