-- This file is automatically loaded by plugins.init local function augroup(name) return vim.api.nvim_create_augroup(name, { clear = true }) end local filetypes = { "makrdown", "gitcommit", "vimwiki", } -- ╭──────────────────────────────────────────────────────────────────────╮ -- │ Reload Changed │ -- ╰──────────────────────────────────────────────────────────────────────╯ vim.api.nvim_create_autocmd({ "FocusGained", "TermClose", "TermLeave" }, { group = augroup("checktime"), command = "checktime", }) -- ╭──────────────────────────────────────────────────────────────────────╮ -- │ Yank highlight │ -- ╰──────────────────────────────────────────────────────────────────────╯ vim.api.nvim_create_autocmd("TextYankPost", { group = augroup("YankHeight"), callback = function() vim.highlight.on_yank({ higroup = "lualine_a_visual", timeout = 100 }) end, }) -- ╭──────────────────────────────────────────────────────────────────────╮ -- │ AsyncRun │ -- ╰──────────────────────────────────────────────────────────────────────╯ vim.api.nvim_create_autocmd("BufLeave", { group = augroup("Asyncrun"), pattern = "*", command = "let g:asyncrun_status='stopped'", }) -- ╭──────────────────────────────────────────────────────────────────────╮ -- │ Resize │ -- ╰──────────────────────────────────────────────────────────────────────╯ -- resize splits if window got resized vim.api.nvim_create_autocmd({ "VimResized" }, { group = augroup("resize_splits"), callback = function() vim.cmd("tabdo wincmd =") end, }) -- ╭──────────────────────────────────────────────────────────────────────╮ -- │ Last open Buffer │ -- ╰──────────────────────────────────────────────────────────────────────╯ -- 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) if mark[1] > 0 and mark[1] <= lcount then pcall(vim.api.nvim_win_set_cursor, 0, mark) end end, }) -- ╭──────────────────────────────────────────────────────────────────────╮ -- │ Smart Quit │ -- ╰──────────────────────────────────────────────────────────────────────╯ vim.api.nvim_create_autocmd("FileType", { group = augroup("close_with_q"), pattern = { "PlenaryTestPopup", "help", "lspinfo", "man", "notify", "qf", "spectre_panel", "startuptime", "tsplayground", "checkhealth", }, callback = function(event) vim.bo[event.buf].buflisted = false vim.keymap.set("n", "q", "close", { buffer = event.buf, silent = true }) end, }) -- ╭──────────────────────────────────────────────────────────────────────╮ -- │ Quickfix │ -- ╰──────────────────────────────────────────────────────────────────────╯ -- wrap and check for spell in text filetypes vim.api.nvim_create_autocmd("FileType", { group = augroup("QuickDisplay"), pattern = "qf", callback = function() vim.opt_local.buflisted = false vim.wo.number = false vim.wo.signcolumn = "no" vim.wo.relativenumber = false vim.wo.cursorline = true end, }) vim.api.nvim_create_autocmd("BufEnter", { group = augroup("QuickDispla_Colory"), pattern = "*", callback = function() if vim.bo.filetype == "qf" then vim.api.nvim_set_hl(0, "QuickFixLine", { fg = "#FFFFFF", bg = "#61AFEF" }) else vim.api.nvim_set_hl(0, "QuickFixLine", { fg = "#Abb2bf", bg = "#282C34" }) end end, }) -- vim.api.nvim_create_autocmd("FileType", { -- group = augroup("AutoCloseWindow"), -- pattern = { "lspinfo", "lsp-installer", "null-ls-info", "help", "qf" }, -- callback = function() -- local opts = { buffer = true, silent = true, desc = "close lspinfo popup and help,qf buffers" } -- vim.keymap.set("n", " 0 and vim.fn.line("'\"") <= vim.fn.line("$") then vim.fn.setpos(".", vim.fn.getpos("'\"")) vim.cmd("silent! foldopen") end end, }) -- ╭──────────────────────────────────────────────────────────────────────╮ -- │ Auto Create Fload │ -- ╰──────────────────────────────────────────────────────────────────────╯ vim.api.nvim_create_autocmd({ "BufWritePre" }, { group = augroup("Auto_Create_Dir"), callback = function(event) if event.match:match("^%w%w+://") then return end local file = vim.loop.fs_realpath(event.match) or event.match vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p") end, }) -- ╭──────────────────────────────────────────────────────────────────────╮ -- │ HideMarkdownChar │ -- ╰──────────────────────────────────────────────────────────────────────╯ vim.api.nvim_create_autocmd({ "FileType" }, { group = augroup("HideMarkdownChar"), callback = function() vim.cmd([[ autocmd FileType vimwiki lua require('../config/utility').HideMarkdownBrackets()]]) end, })