fix(config): add groups to autocommands, and fix plugin/user config order

This commit is contained in:
Tamás Barta 2023-01-29 19:41:28 +01:00
parent 59c32788ae
commit e05d7658fb
No known key found for this signature in database
GPG key ID: 2236CB8759C72657
2 changed files with 14 additions and 2 deletions

View file

@ -4,20 +4,25 @@
vim.api.nvim_create_autocmd({ "FocusGained", "TermClose", "TermLeave" }, { command = "checktime" })
-- Highlight on yank
vim.api.nvim_create_augroup("_lazy_vim_highlight_on_yank", {})
vim.api.nvim_create_autocmd("TextYankPost", {
callback = function()
vim.highlight.on_yank()
end,
group = "_lazy_vim_highlight_on_yank",
})
-- resize splits if window got resized
vim.api.nvim_create_augroup("_lazy_vim_resize_splits", {})
vim.api.nvim_create_autocmd({ "VimResized" }, {
callback = function()
vim.cmd("tabdo wincmd =")
end,
group = "_lazy_vim_resize_splits",
})
-- go to last loc when opening a buffer
vim.api.nvim_create_augroup("_lazy_vim_go_to_last_loc_when_opening_a_buffer", {})
vim.api.nvim_create_autocmd("BufReadPost", {
callback = function()
local mark = vim.api.nvim_buf_get_mark(0, '"')
@ -26,9 +31,11 @@ vim.api.nvim_create_autocmd("BufReadPost", {
pcall(vim.api.nvim_win_set_cursor, 0, mark)
end
end,
group = "_lazy_vim_go_to_last_loc_when_opening_a_buffer",
})
-- close some filetypes with <q>
vim.api.nvim_create_augroup("_lazy_vim_close_some_filetypes_with_q", {})
vim.api.nvim_create_autocmd("FileType", {
pattern = {
"qf",
@ -45,8 +52,11 @@ vim.api.nvim_create_autocmd("FileType", {
vim.bo[event.buf].buflisted = false
vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = event.buf, silent = true })
end,
group = "_lazy_vim_close_some_filetypes_with_q",
})
-- wrap and check for spell in text filetypes
vim.api.nvim_create_augroup("_lazy_vim_wrap_and_spell_check_text_filetypes", {})
vim.api.nvim_create_autocmd("FileType", {
pattern = { "gitcommit", "markdown" },
callback = function()

View file

@ -119,8 +119,7 @@ end
---@param name "autocmds" | "options" | "keymaps"
function M.load(name)
local Util = require("lazy.core.util")
-- always load lazyvim, then user file
for _, mod in ipairs({ "lazyvim.config." .. name, "config." .. name }) do
local try_load = function(mod)
Util.try(function()
require(mod)
end, {
@ -133,6 +132,9 @@ function M.load(name)
end,
})
end
-- always load lazyvim, then user file
try_load("lazyvim.config." .. name)
try_load("config." .. name)
if vim.bo.filetype == "lazy" then
-- HACK: LazyVim may have overwritten options of the Lazy ui, so reset this here
vim.cmd([[do VimResized]])