mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
refactor: autocmd groups
This commit is contained in:
parent
7f02013e5a
commit
ee609eb3d6
1 changed files with 13 additions and 7 deletions
|
|
@ -1,27 +1,34 @@
|
|||
-- This file is automatically loaded by plugins.init
|
||||
|
||||
local function augroup(name)
|
||||
return vim.api.nvim_create_augroup("lazyvim_" .. name, { clear = true })
|
||||
end
|
||||
|
||||
-- Check if we need to reload the file when it changed
|
||||
vim.api.nvim_create_autocmd({ "FocusGained", "TermClose", "TermLeave" }, { command = "checktime" })
|
||||
vim.api.nvim_create_autocmd({ "FocusGained", "TermClose", "TermLeave" }, {
|
||||
group = augroup("checktime"),
|
||||
command = "checktime",
|
||||
})
|
||||
|
||||
-- Highlight on yank
|
||||
vim.api.nvim_create_autocmd("TextYankPost", {
|
||||
group = augroup("highlight_yank"),
|
||||
callback = function()
|
||||
vim.highlight.on_yank()
|
||||
end,
|
||||
group = vim.api.nvim_create_augroup("_lazy_vim_highlight_on_yank", { clear = true }),
|
||||
})
|
||||
|
||||
-- resize splits if window got resized
|
||||
vim.api.nvim_create_augroup("_lazy_vim_resize_splits", { clear = true })
|
||||
vim.api.nvim_create_autocmd({ "VimResized" }, {
|
||||
group = augroup("resize_splits"),
|
||||
callback = function()
|
||||
vim.cmd("tabdo wincmd =")
|
||||
end,
|
||||
group = "_lazy_vim_resize_splits",
|
||||
})
|
||||
|
||||
-- go to last loc when opening a buffer
|
||||
vim.api.nvim_create_autocmd("BufReadPost", {
|
||||
group = augroup("last_loc"),
|
||||
callback = function()
|
||||
local mark = vim.api.nvim_buf_get_mark(0, '"')
|
||||
local lcount = vim.api.nvim_buf_line_count(0)
|
||||
|
|
@ -29,11 +36,11 @@ vim.api.nvim_create_autocmd("BufReadPost", {
|
|||
pcall(vim.api.nvim_win_set_cursor, 0, mark)
|
||||
end
|
||||
end,
|
||||
group = vim.api.nvim_create_augroup("_lazy_vim_go_to_last_loc_when_opening_a_buffer", { clear = true }),
|
||||
})
|
||||
|
||||
-- close some filetypes with <q>
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
group = augroup("close_with_q"),
|
||||
pattern = {
|
||||
"qf",
|
||||
"help",
|
||||
|
|
@ -49,15 +56,14 @@ 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 = vim.api.nvim_create_augroup("_lazy_vim_close_some_filetypes_with_q", { clear = true }),
|
||||
})
|
||||
|
||||
-- wrap and check for spell in text filetypes
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
group = augroup("wrap_spell"),
|
||||
pattern = { "gitcommit", "markdown" },
|
||||
callback = function()
|
||||
vim.opt_local.wrap = true
|
||||
vim.opt_local.spell = true
|
||||
end,
|
||||
group = vim.api.nvim_create_augroup("_lazy_vim_wrap_and_spell_check_text_filetypes", { clear = true }),
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue