local augroups = {
    bufs = {
        -- Reload vim config automatically
        { 'BufWritePost', '$VIM_PATH/{*.vim,*.yaml,*.yml,vimrc}', 'nested source $MYVIMRC | redraw' },
        -- Reload Vim script automatically if setlocal autoread
        {
            'BufWritePost,FileWritePost',
            '*.vim',
            [[nested if &l:autoread > 0 | source <afile> | echo 'source ' . bufname('%') | endif]],
        },
        -- No undo for temporary files
        { 'BufWritePre', '/tmp/*', 'setlocal noundofile' },
        { 'BufWritePre', 'COMMIT_EDITMSG', 'setlocal noundofile' },
        { 'BufWritePre', 'MERGE_MSG', 'setlocal noundofile' },
        { 'BufWritePre', '*.tmp', 'setlocal noundofile' },
        { 'BufWritePre', '*.bak', 'setlocal noundofile' },
    },
    ft = {
        -- Set wrap and nonumber for text files
        { 'FileType', 'asciidoc,gemini,markdown,tex', 'setlocal wrap nonumber norelativenumber' },
        -- Keep git commits short
        { 'FileType', 'gitcommit', 'setlocal colorcolumn=80' },
    },
    wins = {
        -- Equalize window dimensions when resizing vim window
        { 'VimResized', '*', 'tabdo wincmd =' },
        -- Force writing shada on leaving nvim
        { 'VimLeave', '*', [[if has('nvim') | wshada! | else | wviminfo! | endif]] },
        -- Check if file changed when its window is focus, more eager than 'autoread'
        { 'FocusGained', '* checktime' },
    },
    yank = {
        { 'TextYankPost', [[* silent! lua vim.highlight.on_yank({higroup='IncSearch', timeout=300})]] },
    },
    keymaps = {
        { 'BufReadPre', '*', 'lua require("user.keymap").whichkeyLocal()' },
        { 'FileType', 'org', 'lua require("user.keymap").whichkeyOrg()' },
        { 'FileType', 'tex', 'lua require("user.keymap").whichkeyTex()' },
        { 'FileType', 'markdown', 'lua require("user.keymap").whichkeyMarkdown()' },
    },
    plugins = {
        -- Autohide tabline on dashboard
        { 'User', 'AlphaReady', 'set showtabline=0 | autocmd BufUnload <buffer> set showtabline=2' },
        -- Wrap in Telescope preview window
        { 'User', 'TelescopePreviewerLoaded', 'setlocal wrap' },
        -- Packer compile on save
        -- { 'BufWritePost', '*.lua', 'lua require("user.plugins").compile_on_save()' },
        -- Packer compile ahead to bytecode and print a notification when done
        { 'User', 'PackerCompileDone', 'lua require("user.plugins").on_compile_done()' },
    },
}

require('user.util').load_autocmd(augroups)
