mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
refactore(autocmds): use autocmd in place of vim.api.nvim_create_autocmd
This commit is contained in:
parent
6e7ba50141
commit
e448439e33
1 changed files with 11 additions and 9 deletions
|
|
@ -4,8 +4,10 @@ local function augroup(name)
|
||||||
return vim.api.nvim_create_augroup("lazyvim_" .. name, { clear = true })
|
return vim.api.nvim_create_augroup("lazyvim_" .. name, { clear = true })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local autocmd = vim.api.nvim_create_autocmd
|
||||||
|
|
||||||
-- Check if we need to reload the file when it changed
|
-- Check if we need to reload the file when it changed
|
||||||
vim.api.nvim_create_autocmd({ "FocusGained", "TermClose", "TermLeave" }, {
|
autocmd({ "FocusGained", "TermClose", "TermLeave" }, {
|
||||||
group = augroup("checktime"),
|
group = augroup("checktime"),
|
||||||
callback = function()
|
callback = function()
|
||||||
if vim.o.buftype ~= "nofile" then
|
if vim.o.buftype ~= "nofile" then
|
||||||
|
|
@ -15,7 +17,7 @@ vim.api.nvim_create_autocmd({ "FocusGained", "TermClose", "TermLeave" }, {
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Highlight on yank
|
-- Highlight on yank
|
||||||
vim.api.nvim_create_autocmd("TextYankPost", {
|
autocmd("TextYankPost", {
|
||||||
group = augroup("highlight_yank"),
|
group = augroup("highlight_yank"),
|
||||||
callback = function()
|
callback = function()
|
||||||
vim.highlight.on_yank()
|
vim.highlight.on_yank()
|
||||||
|
|
@ -23,7 +25,7 @@ vim.api.nvim_create_autocmd("TextYankPost", {
|
||||||
})
|
})
|
||||||
|
|
||||||
-- resize splits if window got resized
|
-- resize splits if window got resized
|
||||||
vim.api.nvim_create_autocmd({ "VimResized" }, {
|
autocmd({ "VimResized" }, {
|
||||||
group = augroup("resize_splits"),
|
group = augroup("resize_splits"),
|
||||||
callback = function()
|
callback = function()
|
||||||
local current_tab = vim.fn.tabpagenr()
|
local current_tab = vim.fn.tabpagenr()
|
||||||
|
|
@ -33,7 +35,7 @@ vim.api.nvim_create_autocmd({ "VimResized" }, {
|
||||||
})
|
})
|
||||||
|
|
||||||
-- go to last loc when opening a buffer
|
-- go to last loc when opening a buffer
|
||||||
vim.api.nvim_create_autocmd("BufReadPost", {
|
autocmd("BufReadPost", {
|
||||||
group = augroup("last_loc"),
|
group = augroup("last_loc"),
|
||||||
callback = function(event)
|
callback = function(event)
|
||||||
local exclude = { "gitcommit" }
|
local exclude = { "gitcommit" }
|
||||||
|
|
@ -51,7 +53,7 @@ vim.api.nvim_create_autocmd("BufReadPost", {
|
||||||
})
|
})
|
||||||
|
|
||||||
-- close some filetypes with <q>
|
-- close some filetypes with <q>
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
autocmd("FileType", {
|
||||||
group = augroup("close_with_q"),
|
group = augroup("close_with_q"),
|
||||||
pattern = {
|
pattern = {
|
||||||
"PlenaryTestPopup",
|
"PlenaryTestPopup",
|
||||||
|
|
@ -74,7 +76,7 @@ vim.api.nvim_create_autocmd("FileType", {
|
||||||
})
|
})
|
||||||
|
|
||||||
-- make it easier to close man-files when opened inline
|
-- make it easier to close man-files when opened inline
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
autocmd("FileType", {
|
||||||
group = augroup("man_unlisted"),
|
group = augroup("man_unlisted"),
|
||||||
pattern = { "man" },
|
pattern = { "man" },
|
||||||
callback = function(event)
|
callback = function(event)
|
||||||
|
|
@ -83,7 +85,7 @@ vim.api.nvim_create_autocmd("FileType", {
|
||||||
})
|
})
|
||||||
|
|
||||||
-- wrap and check for spell in text filetypes
|
-- wrap and check for spell in text filetypes
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
autocmd("FileType", {
|
||||||
group = augroup("wrap_spell"),
|
group = augroup("wrap_spell"),
|
||||||
pattern = { "gitcommit", "markdown" },
|
pattern = { "gitcommit", "markdown" },
|
||||||
callback = function()
|
callback = function()
|
||||||
|
|
@ -93,7 +95,7 @@ vim.api.nvim_create_autocmd("FileType", {
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Fix conceallevel for json files
|
-- Fix conceallevel for json files
|
||||||
vim.api.nvim_create_autocmd({ "FileType" }, {
|
autocmd({ "FileType" }, {
|
||||||
group = augroup("json_conceal"),
|
group = augroup("json_conceal"),
|
||||||
pattern = { "json", "jsonc", "json5" },
|
pattern = { "json", "jsonc", "json5" },
|
||||||
callback = function()
|
callback = function()
|
||||||
|
|
@ -102,7 +104,7 @@ vim.api.nvim_create_autocmd({ "FileType" }, {
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Auto create dir when saving a file, in case some intermediate directory does not exist
|
-- Auto create dir when saving a file, in case some intermediate directory does not exist
|
||||||
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
autocmd({ "BufWritePre" }, {
|
||||||
group = augroup("auto_create_dir"),
|
group = augroup("auto_create_dir"),
|
||||||
callback = function(event)
|
callback = function(event)
|
||||||
if event.match:match("^%w%w+:[\\/][\\/]") then
|
if event.match:match("^%w%w+:[\\/][\\/]") then
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue