2023-05-19 14:06:59 +01:00
|
|
|
-- This file is automatically loaded by lazyvim.config.init
|
2023-01-03 23:51:57 +01:00
|
|
|
|
2023-02-07 20:30:46 +01:00
|
|
|
local function augroup(name)
|
|
|
|
return vim.api.nvim_create_augroup("lazyvim_" .. name, { clear = true })
|
|
|
|
end
|
|
|
|
|
2022-12-30 17:30:52 +01:00
|
|
|
-- Check if we need to reload the file when it changed
|
2023-02-07 20:30:46 +01:00
|
|
|
vim.api.nvim_create_autocmd({ "FocusGained", "TermClose", "TermLeave" }, {
|
|
|
|
group = augroup("checktime"),
|
|
|
|
command = "checktime",
|
|
|
|
})
|
2022-12-30 17:30:52 +01:00
|
|
|
|
|
|
|
-- Highlight on yank
|
2022-12-30 18:21:25 +01:00
|
|
|
vim.api.nvim_create_autocmd("TextYankPost", {
|
2023-02-07 20:30:46 +01:00
|
|
|
group = augroup("highlight_yank"),
|
2022-12-30 18:21:25 +01:00
|
|
|
callback = function()
|
|
|
|
vim.highlight.on_yank()
|
|
|
|
end,
|
|
|
|
})
|
2022-12-30 17:30:52 +01:00
|
|
|
|
2023-01-11 16:26:08 +01:00
|
|
|
-- resize splits if window got resized
|
|
|
|
vim.api.nvim_create_autocmd({ "VimResized" }, {
|
2023-02-07 20:30:46 +01:00
|
|
|
group = augroup("resize_splits"),
|
2023-01-11 16:26:08 +01:00
|
|
|
callback = function()
|
|
|
|
vim.cmd("tabdo wincmd =")
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2022-12-30 17:30:52 +01:00
|
|
|
-- go to last loc when opening a buffer
|
2022-12-31 14:30:12 +01:00
|
|
|
vim.api.nvim_create_autocmd("BufReadPost", {
|
2023-02-07 20:30:46 +01:00
|
|
|
group = augroup("last_loc"),
|
2022-12-30 17:30:52 +01:00
|
|
|
callback = function()
|
2023-01-02 17:36:49 +01:00
|
|
|
local mark = vim.api.nvim_buf_get_mark(0, '"')
|
|
|
|
local lcount = vim.api.nvim_buf_line_count(0)
|
|
|
|
if mark[1] > 0 and mark[1] <= lcount then
|
|
|
|
pcall(vim.api.nvim_win_set_cursor, 0, mark)
|
|
|
|
end
|
2022-12-30 17:30:52 +01:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
-- close some filetypes with <q>
|
2023-01-06 23:51:02 +01:00
|
|
|
vim.api.nvim_create_autocmd("FileType", {
|
2023-02-07 20:30:46 +01:00
|
|
|
group = augroup("close_with_q"),
|
2022-12-30 17:30:52 +01:00
|
|
|
pattern = {
|
2023-03-04 10:40:00 +01:00
|
|
|
"PlenaryTestPopup",
|
2022-12-30 17:30:52 +01:00
|
|
|
"help",
|
2023-03-04 10:40:00 +01:00
|
|
|
"lspinfo",
|
2022-12-30 17:30:52 +01:00
|
|
|
"man",
|
|
|
|
"notify",
|
2023-03-04 10:40:00 +01:00
|
|
|
"qf",
|
2022-12-30 17:30:52 +01:00
|
|
|
"spectre_panel",
|
|
|
|
"startuptime",
|
|
|
|
"tsplayground",
|
2023-04-16 18:39:12 +10:00
|
|
|
"checkhealth",
|
2023-05-22 20:57:15 +02:00
|
|
|
"neotest-output",
|
2022-12-30 17:30:52 +01:00
|
|
|
},
|
|
|
|
callback = function(event)
|
|
|
|
vim.bo[event.buf].buflisted = false
|
|
|
|
vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = event.buf, silent = true })
|
|
|
|
end,
|
|
|
|
})
|
2023-01-06 23:51:02 +01:00
|
|
|
|
2023-02-07 20:30:46 +01:00
|
|
|
-- wrap and check for spell in text filetypes
|
2023-01-06 23:51:02 +01:00
|
|
|
vim.api.nvim_create_autocmd("FileType", {
|
2023-02-07 20:30:46 +01:00
|
|
|
group = augroup("wrap_spell"),
|
2023-01-06 23:51:02 +01:00
|
|
|
pattern = { "gitcommit", "markdown" },
|
|
|
|
callback = function()
|
|
|
|
vim.opt_local.wrap = true
|
|
|
|
vim.opt_local.spell = true
|
|
|
|
end,
|
|
|
|
})
|
2023-03-31 14:40:57 +07:00
|
|
|
|
|
|
|
-- Auto create dir when saving a file, in case some intermediate directory does not exist
|
|
|
|
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
|
|
|
group = augroup("auto_create_dir"),
|
|
|
|
callback = function(event)
|
2023-04-16 07:53:42 +02:00
|
|
|
if event.match:match("^%w%w+://") then
|
|
|
|
return
|
|
|
|
end
|
2023-03-31 14:40:57 +07:00
|
|
|
local file = vim.loop.fs_realpath(event.match) or event.match
|
|
|
|
vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p")
|
|
|
|
end,
|
|
|
|
})
|