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
|
|
|
|
vim.api.nvim_command('PackerCompile')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.nvim_create_augroups(definitions)
|
2021-07-04 15:03:20 -04:00
|
|
|
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 = {
|
|
|
|
packer = {
|
2021-07-04 15:03:20 -04:00
|
|
|
{"BufWritePost", "*.lua", "lua require('events').packer_compile()"}
|
|
|
|
},
|
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 = {
|
2021-07-04 15:03:20 -04:00
|
|
|
{"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
|
|
|
|
2021-07-04 15:03:20 -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
|
|
|
|
{"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
|
|
|
|
|
|
|
wins = {
|
|
|
|
-- Equalize window dimensions when resizing vim window
|
2021-07-04 15:03:20 -04:00
|
|
|
{"VimResized", "*", [[tabdo wincmd =]]},
|
|
|
|
-- Force writing shada on leaving nvim
|
|
|
|
{"VimLeave", "*", [[if has('nvim') | wshada! | else | wviminfo! | endif]]},
|
2021-07-03 20:19:46 -04:00
|
|
|
-- Check if file changed when its window is focus, more eager than 'autoread'
|
2021-07-04 15:03:20 -04:00
|
|
|
{"FocusGained", "* checktime"}
|
|
|
|
},
|
|
|
|
|
|
|
|
ft = {
|
|
|
|
{"FileType", "dashboard", "set showtabline=0 | autocmd WinLeave <buffer> set showtabline=2"},
|
|
|
|
{"BufNewFile,BufRead", "*.md,*.mkd", "setfiletype markdown"},
|
|
|
|
{"BufNewFile,BufRead", "*.toml", "setfiletype toml"},
|
|
|
|
{"BufNewFile,BufRead", "*.tex", "setfiletype tex"}
|
|
|
|
},
|
2021-07-03 20:19:46 -04:00
|
|
|
|
|
|
|
yank = {
|
2021-07-04 15:03:20 -04:00
|
|
|
{"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
|