FollieHiyuki-dotfiles/home/.config/nvim/lua/autocmd.lua

42 lines
1.6 KiB
Lua
Raw Normal View History

local definitions = {
-- ':h hex-editing'
-- binary = {
-- {'BufReadPre' , '*.bin,*.exe', 'let &bin=1'},
-- {'BufReadPost' , '*.bin,*.exe', 'if &bin | %!xxd'},
-- {'BufReadPost' , '*.bin,*.exe', 'set ft=xxd | endif'},
-- {'BufWritePre' , '*.bin,*.exe', 'if &bin | %!xxd -r'},
-- {'BufWritePre' , '*.bin,*.exe', 'endif'},
-- {'BufWritePost', '*.bin,*.exe', 'if &bin | %!xxd'},
-- {'BufWritePost', '*.bin,*.exe', 'set nomod | endif'}
-- },
-- Auto-hide UI elements in specific buffers
-- buf = {
-- {'BufEnter', 'term://*', 'setlocal norelativenumber nonumber'},
-- {'BufEnter,BufWinEnter,WinEnter,CmdwinEnter', '*', [[if bufname('%') == 'NvimTree' | set laststatus=0 | else | set laststatus=2 | endif]]}
-- },
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})]]}
}
}
for group_name, definition in pairs(definitions) do
vim.api.nvim_command('augroup ' .. group_name)
vim.api.nvim_command('autocmd!')
for _, def in ipairs(definition) do
local command = table.concat(vim.tbl_flatten{'autocmd', def}, ' ')
vim.api.nvim_command(command)
end
vim.api.nvim_command('augroup END')
end