2023-07-04 19:06:13 +02: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"),
|
2024-01-22 06:20:54 +11:00
|
|
|
callback = function()
|
2024-03-07 12:00:44 +01:00
|
|
|
if vim.o.buftype ~= "nofile" then
|
|
|
|
vim.cmd("checktime")
|
2024-01-22 06:20:54 +11:00
|
|
|
end
|
2024-03-07 12:00:44 +01:00
|
|
|
end,
|
2023-02-07 20:30:46 +01:00
|
|
|
})
|
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()
|
2023-08-30 02:13:32 +10:00
|
|
|
local current_tab = vim.fn.tabpagenr()
|
2023-01-11 16:26:08 +01:00
|
|
|
vim.cmd("tabdo wincmd =")
|
2023-08-30 02:13:32 +10:00
|
|
|
vim.cmd("tabnext " .. current_tab)
|
2023-01-11 16:26:08 +01:00
|
|
|
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"),
|
2023-10-04 10:48:20 +02:00
|
|
|
callback = function(event)
|
2023-06-30 08:35:26 +02:00
|
|
|
local exclude = { "gitcommit" }
|
2023-10-04 10:48:20 +02:00
|
|
|
local buf = event.buf
|
2023-10-09 20:11:05 +02:00
|
|
|
if vim.tbl_contains(exclude, vim.bo[buf].filetype) or vim.b[buf].lazyvim_last_loc then
|
2023-06-30 08:35:26 +02:00
|
|
|
return
|
|
|
|
end
|
2023-10-09 20:11:05 +02:00
|
|
|
vim.b[buf].lazyvim_last_loc = true
|
2023-06-30 08:35:26 +02:00
|
|
|
local mark = vim.api.nvim_buf_get_mark(buf, '"')
|
|
|
|
local lcount = vim.api.nvim_buf_line_count(buf)
|
2023-01-02 17:36:49 +01:00
|
|
|
if mark[1] > 0 and mark[1] <= lcount then
|
2023-07-06 08:43:15 -05:00
|
|
|
pcall(vim.api.nvim_win_set_cursor, 0, mark)
|
2023-01-02 17:36:49 +01:00
|
|
|
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
|
|
|
"notify",
|
2023-03-04 10:40:00 +01:00
|
|
|
"qf",
|
2022-12-30 17:30:52 +01:00
|
|
|
"spectre_panel",
|
|
|
|
"startuptime",
|
|
|
|
"tsplayground",
|
2023-05-22 20:57:15 +02:00
|
|
|
"neotest-output",
|
2023-05-27 09:35:49 +02:00
|
|
|
"checkhealth",
|
|
|
|
"neotest-summary",
|
|
|
|
"neotest-output-panel",
|
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
|
|
|
|
2024-03-07 11:38:36 +01:00
|
|
|
-- make it easier to close man-files when opened inline
|
|
|
|
vim.api.nvim_create_autocmd("FileType", {
|
|
|
|
group = augroup("man_unlisted"),
|
|
|
|
pattern = { "man" },
|
|
|
|
callback = function(event)
|
|
|
|
vim.bo[event.buf].buflisted = false
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
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
|
|
|
|
2024-01-21 11:24:59 +01:00
|
|
|
-- Fix conceallevel for json files
|
|
|
|
vim.api.nvim_create_autocmd({ "FileType" }, {
|
|
|
|
group = augroup("json_conceal"),
|
|
|
|
pattern = { "json", "jsonc", "json5" },
|
|
|
|
callback = function()
|
2024-01-23 01:51:34 -05:00
|
|
|
vim.opt_local.conceallevel = 0
|
2024-01-21 11:24:59 +01:00
|
|
|
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)
|
2024-03-26 20:48:50 +01:00
|
|
|
if event.match:match("^%w%w+:[\\/][\\/]") then
|
2023-04-16 07:53:42 +02:00
|
|
|
return
|
|
|
|
end
|
2024-03-22 09:02:34 +01:00
|
|
|
local file = vim.uv.fs_realpath(event.match) or event.match
|
2023-03-31 14:40:57 +07:00
|
|
|
vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p")
|
|
|
|
end,
|
|
|
|
})
|