dotfiles-ansible/roles/nvim/files/nvim/lua/autocmd.lua
Hoang Nguyen 1cc8d84e41
nvim: move packer autocmd back; remove detect-language.nvim
The plugins' configurations are lazy-loaded, so better not doing the
autocmd early (improve startup time a little bit)
2021-11-30 13:46:49 +07:00

76 lines
2.7 KiB
Lua

local M = {}
function Lightbulb_codeaction()
local present, lightbulb = pcall(require, 'nvim-lightbulb')
if present then
lightbulb.update_lightbulb {
sign = {enabled = false},
status_text = {
enabled = true,
text = ' Code action',
text_unavailable = ''
}
}
end
end
-- cd on local window changes with 'lcd' (more eager)
-- see https://github.com/ahmedkhalf/project.nvim/issues/23
-- function Set_window_project_dir()
-- local present, project = pcall(require, 'project_nvim.project')
-- if present then
-- local root, _ = project.get_project_root()
-- if root then
-- vim.api.nvim_command('lcd ' .. root)
-- end
-- end
-- end
local augroups = {
bufs = {
-- Reload vim config automatically
{'BufWritePost', [[$VIM_PATH/{*.vim,*.yaml,vimrc} nested source $MYVIMRC | redraw]]},
-- Reload Vim script automatically if setlocal autoread
{'BufWritePost,FileWritePost', '*.vim', [[nested if &l:autoread > 0 | source <afile> | echo 'source ' . bufname('%') | endif]]},
-- No undo for temporary files
{'BufWritePre', '/tmp/*', 'setlocal noundofile'},
{'BufWritePre', 'COMMIT_EDITMSG', 'setlocal noundofile'},
{'BufWritePre', 'MERGE_MSG', 'setlocal noundofile'},
{'BufWritePre', '*.tmp', 'setlocal noundofile'},
{'BufWritePre', '*.bak', 'setlocal noundofile'}
},
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})]]}
},
mappings = {
{'BufEnter', '*', 'lua WhichkeyLocal()'},
{'FileType', 'org', 'lua WhichkeyOrg()'},
{'FileType', 'html', 'lua WhichkeyHtml()'},
{'FileType', 'markdown', 'lua WhichkeyMarkdown()'}
},
plugins = {
-- Autohide tabline on dashboard
{'FileType', 'alpha', 'set showtabline=0 | autocmd BufUnload <buffer> set showtabline=2'},
-- Wrap in Telescope preview window
{'User', 'TelescopePreviewerLoaded', 'setlocal wrap'},
-- Lsp lightbulb
{'CursorHold', '*', 'lua Lightbulb_codeaction()'},
-- Change directory more eagerly
-- {'BufEnter', '* lua Set_window_project_dir()'}
}
}
function M.setup()
require('util').load_autocmd(augroups)
end
return M