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

87 lines
3.3 KiB
Lua
Raw Normal View History

2021-07-03 20:19:46 -04:00
local plug_dir = vim.fn.stdpath('config') .. '/lua'
local M = {}
function M.packer_compile()
local file = vim.fn.expand('%:p')
if file:match(plug_dir) then
2021-07-10 12:40:43 -04:00
vim.api.nvim_command('source <afile> | PackerCompile')
2021-07-03 20:19:46 -04:00
end
end
function M.nvim_create_augroups(definitions)
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')
2021-07-03 20:19:46 -04:00
end
end
function M.load_autocmds()
local definitions = {
plugins = {
2021-07-10 12:40:43 -04:00
-- Wrap lines in preview window
-- {"User TelescopePreviewerLoaded", [[setlocal wrap]]},
-- Re-compile packer on config changed
{"BufWritePost", "*.lua", "lua require('events').packer_compile()"},
2021-07-10 12:40:43 -04:00
-- Register binding for ToggleTerm inside term mode
{"TermEnter", "term://*toggleterm#*", "tnoremap <silent><C-\\> <C-\\><C-n>:ToggleTerm<CR>"}
},
2021-07-03 20:19:46 -04:00
-- Edit binary files in hex with xxd (:%!xxd and :%!xxd -r)
-- or using nvim -b to edit files using xxd-format
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"}
},
2021-07-03 20:19:46 -04:00
buf = {
-- Auto-spelling in doc files
{"BufNewFile,BufRead", "*.md,*.mkd", "setlocal spell"},
{"BufNewFile,BufRead", "*.tex", "setlocal spell"},
-- Auto-hide numbers, statusline in specific buffers
2021-07-10 12:40:43 -04:00
-- {"BufEnter", "term://*", "setlocal norelativenumber nonumber"},
-- {"BufEnter", "term://*", "set laststatus=0"},
-- {"BufEnter,BufWinEnter,WinEnter,CmdwinEnter", "*", [[if bufname('%') == "NvimTree" | set laststatus=0 | else | set laststatus=2 | endif]]}
},
2021-07-03 20:19:46 -04:00
2021-08-31 11:58:15 -04:00
wins = {
-- Equalize window dimensions when resizing vim window
{"VimResized", "*", [[tabdo wincmd =]]},
2021-08-31 11:58:15 -04:00
-- Force writing shada on leaving nvim
{"VimLeave", "*", [[if has('nvim') | wshada! | else | wviminfo! | endif]]},
2021-08-31 11:58:15 -04:00
-- 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"},
2021-07-10 12:40:43 -04:00
{"BufNewFile,BufRead", "*.rasi", "setfiletype css"},
{"BufNewFile,BufRead", "vifmrc,*.vifm", "setfiletype vim"},
{"BufNewFile,BufRead", "*.log,*_log,*.LO,G*_LOG", "setfiletype log"}
},
2021-07-03 20:19:46 -04:00
yank = {
{"TextYankPost", [[* silent! lua vim.highlight.on_yank({higroup="IncSearch", timeout=300})]]}
}
2021-07-03 20:19:46 -04:00
}
M.nvim_create_augroups(definitions)
end
return M