FollieHiyuki-dotfiles/home/.config/nvim/lua/autocmd.lua
2021-10-17 21:48:12 +07:00

50 lines
1.9 KiB
Lua

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'}
},
ft = {
{'BufNewFile,BufRead', '*.md,*.mkd', 'setfiletype markdown'},
{'BufNewFile,BufRead', '*.toml', 'setfiletype toml'},
{'BufNewFile,BufRead', '*.rasi', 'setfiletype css'},
{'BufNewFile,BufRead', 'vifmrc,*.vifm', 'setfiletype vim'},
{'BufNewFile,BufRead', '*.log,*_log,*.LO,G*_LOG', 'setfiletype log'}
},
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