From 4b47ecacd82fd825bb453f52d7830aa854cfe05b Mon Sep 17 00:00:00 2001 From: Henrik Bakken Date: Wed, 2 Apr 2025 10:55:11 +0200 Subject: [PATCH] nvim autocmds - close special filetypes with q - auto spellcheck and wrap --- nvim/init.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/nvim/init.lua b/nvim/init.lua index 7033eba..62bf1f5 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -191,6 +191,7 @@ map( -- LSP map("n", "ll", "e ~/.local/state/nvim/lsp.log") +map("n", "lc", "checkhealth") local diagnostic_goto = function(count, severity) severity = severity and vim.diagnostic.severity[severity] or nil return function() vim.diagnostic.jump({ severity, float = true, count = count }) end @@ -238,6 +239,42 @@ vim.api.nvim_create_autocmd("BufEnter", { pattern = "*", command = "if &buftype == '' && !&modified && expand('%') != '' | exec 'checktime ' . expand('') | endif", }) +-- Close some filetypes with +vim.api.nvim_create_autocmd("FileType", { + group = vim.api.nvim_create_augroup("close_with_q", { clear = true }), + pattern = { + "PlenaryTestPopup", + "checkhealth", + "floggraph", + "fugitive", + "gitsigns-blame", + "grug-far", + "help", + "lspinfo", + "notify", + "oil", + "qf", + }, + callback = function(event) + vim.bo[event.buf].buflisted = false + vim.schedule(function() + vim.keymap.set("n", "q", function() + vim.cmd("close") + pcall(vim.api.nvim_buf_delete, event.buf, { force = true }) + end, { buffer = event.buf, silent = true, desc = "Quit Buffer" }) + end) + end, +}) + +-- wrap and check for spell in text filetypes +vim.api.nvim_create_autocmd("FileType", { + group = vim.api.nvim_create_augroup("wrap_spell", { clear = true }), + pattern = { "text", "plaintex", "typst", "gitcommit", "markdown" }, + callback = function() + vim.opt_local.wrap = true + vim.opt_local.spell = true + end, +}) -- ---------------------------------------- -- SPECS