dotfiles-ansible/roles/nvim/files/nvim/lua/user/autocmd.lua

207 lines
6.4 KiB
Lua

local augroups = {
bufs = {
-- {
-- event = { 'BufWritePost', 'FileWritePost' },
-- opts = {
-- pattern = '*.vim',
-- nested = true,
-- command = 'if &l:autoread > 0 | source <afile> | echo "source " . bufname("%") | endif',
-- desc = 'Reload Vim script automatically if setlocal autoread',
-- },
-- },
{
event = 'BufWritePre',
opts = {
pattern = { '/tmp/*', 'COMMIT_EDITMSG', 'MERGE_MSG', '*.tmp', '*.bak' },
callback = function(args)
vim.opt_local.undofile = false
end,
desc = 'No undo for temporary files',
},
},
},
ft = {
{
event = 'FileType',
opts = {
pattern = { 'asciidoc', 'gemini', 'markdown', 'tex' },
callback = function(args)
vim.opt_local.wrap = true
vim.opt_local.number = false
vim.opt_local.relativenumber = false
end,
desc = 'Set wrap and nonumber for document files',
},
},
{
event = 'FileType',
opts = {
pattern = 'gitcommit',
callback = function(args)
vim.opt_local.colorcolumn = { 80 }
end,
desc = 'Keep gitcommit messages short'
},
},
},
wins = {
{
event = 'VimResized',
opts = {
pattern = '*',
command = 'tabdo wincmd =',
desc = 'Equalize window dimensions when resizing vim window',
},
},
{
event = 'VimLeave',
opts = {
pattern = '*',
command = 'if has("nvim") | wshada! | else | wviminfo! | endif',
desc = 'Force writing shada file on leaving nvim',
},
},
-- More eager than 'autoread'
{
event = 'FocusGained',
opts = {
pattern = '*',
command = 'checktime',
desc = 'Check whether the file changed when its window is focused',
},
},
},
keymaps = {
{
event = 'BufReadPre',
opts = {
pattern = '*',
callback = function(args)
require('user.keymap').whichkeyLocal()
end,
desc = 'Setup key bindings for localleader',
},
},
{
event = 'FileType',
opts = {
pattern = 'org',
callback = function(args)
require('user.keymap').whichkeyOrg()
end,
desc = 'Setup key bindings for Org files',
},
},
{
event = 'FileType',
opts = {
pattern = 'tex',
callback = function(args)
require('user.keymap').whichkeyTex()
end,
desc = 'Setup key bindings for LaTEX files',
},
},
{
event = 'FileType',
opts = {
pattern = 'markdown',
callback = function(args)
require('user.keymap').whichkeyMarkdown()
end,
desc = 'Setup key bindings for Markdown files',
},
},
},
plugins = {
{
event = 'User',
opts = {
pattern = 'TelescopePreviewerLoaded',
callback = function(args)
vim.opt_local.wrap = true
end,
desc = 'Wrap lines in Telescope preview window',
}
},
{
event = 'User',
opts = {
pattern = 'LeapEnter',
callback = function(args)
vim.opt_local.conceallevel = 0
end,
desc = 'Disable conceal on entering leap.nvim',
},
},
{
event = 'User',
opts = {
pattern = 'LeapLeave',
callback = function(args)
vim.opt_local.conceallevel = vim.opt.conceallevel:get()
end,
desc = 'Restore conceal level on leaving leap.nvim',
},
},
-- {
-- event = 'BufWritePost',
-- opts = {
-- pattern = '*.lua',
-- callback = function(args)
-- require('user.plugins').compile_on_save()
-- end,
-- desc = 'Packer compile on save',
-- },
-- },
{
event = 'User',
opts = {
pattern = 'PackerCompileDone',
callback = function(args)
require('user.plugins').on_compile_done()
end,
desc = 'Packer compile ahead to LuaJIT bytecode and print notification when done',
},
},
},
highlight = {
{
event = 'TextYankPost',
opts = {
pattern = '*',
callback = function(args)
vim.highlight.on_yank({ higroup = 'IncSearch', timeout = 300 })
end,
desc = 'Highlight yanked region',
},
},
-- see :help hl-StatusLineTerm
{
event = { 'TermOpen', 'WinEnter' },
opts = {
pattern = '*',
callback = function(args)
local buftype = vim.api.nvim_buf_get_option(args.buf, 'buftype')
if buftype == 'terminal' then
vim.opt_local.winhighlight = 'Normal:NormalFloat,SignColumn:NormalFloat'
end
end,
desc = 'Override terminal window highlight',
}
},
{
event = 'FileType',
opts = {
pattern = 'packer',
callback = function(args)
vim.opt_local.winhighlight = 'Normal:NormalFloat,SignColumn:NormalFloat'
end,
desc = 'Override Packer window highlight',
}
},
},
}
require('user.utils.functions').load_autocmd(augroups)