vim.cmd([[autocmd FileType markdown nnoremap gO Toc]]) vim.cmd([[autocmd FileType markdown setlocal spell]]) -- Check if we need to reload the file when it changed vim.cmd("au FocusGained * :checktime") -- show cursor line only in active window vim.api.nvim_create_autocmd({ "InsertLeave", "WinEnter" }, { callback = function() local ok, cl = pcall(vim.api.nvim_win_get_var, 0, "auto-cursorline") if ok and cl then vim.wo.cursorline = true vim.api.nvim_win_del_var(0, "auto-cursorline") end end, }) vim.api.nvim_create_autocmd({ "InsertEnter", "WinLeave" }, { callback = function() local cl = vim.wo.cursorline if cl then vim.api.nvim_win_set_var(0, "auto-cursorline", cl) vim.wo.cursorline = false end end, }) -- create directories when needed, when saving a file vim.api.nvim_create_autocmd("BufWritePre", { group = vim.api.nvim_create_augroup("auto_create_dir", { clear = true }), callback = function(event) local file = vim.loop.fs_realpath(event.match) or event.match vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p") local backup = vim.fn.fnamemodify(file, ":p:~:h") backup = backup:gsub("[/\\]", "%%") vim.go.backupext = backup end, }) -- Fix conceallevel for json & help files vim.api.nvim_create_autocmd({ "FileType" }, { pattern = { "json", "jsonc" }, callback = function() vim.wo.spell = false vim.wo.conceallevel = 0 end, }) -- go to last loc when opening a buffer vim.api.nvim_create_autocmd("BufReadPre", { pattern = "*", callback = function() vim.api.nvim_create_autocmd("FileType", { pattern = "", once = true, callback = function() vim.cmd( [[if &ft !~# 'commit\|rebase' && line("'\"") > 1 && line("'\"") <= line("$") | exe 'normal! g`"' | endif]] ) end, }) end, }) -- local reloaded_id = nil -- vim.api.nvim_create_autocmd("BufWritePost", { -- pattern = "*.lua", -- callback = function(event) -- ---@type string -- local file = event.match -- local mod = file:match("/lua/(.*)%.lua") -- if mod then -- mod = mod:gsub("/", ".") -- end -- if mod and package.loaded[mod] then -- package.loaded[mod] = nil -- reloaded_id = vim.notify("Reloaded " .. mod, vim.log.levels.INFO, { title = "nvim", replace = reloaded_id }) -- end -- end, -- }) -- Highlight on yank vim.cmd("au TextYankPost * lua vim.highlight.on_yank {}") vim.api.nvim_create_autocmd({ "FileType" }, { pattern = { "qf", "help", "man", "notify", "lspinfo", "spectre_panel", "startuptime", "tsplayground", "PlenaryTestPopup", }, callback = function() vim.cmd([[ nnoremap q close set nobuflisted ]]) end, })