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

View file

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