From 5c7dffe3782c18e0d47f5753a8c30a0cd1b6e352 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Mon, 16 Sep 2024 18:06:11 +0200 Subject: checkpoint - made keybinds more logical with prefixes - renamed user to config - updated to-do's - added rounded borders on floating windows - added vim-eunuch - added telescope-symbols --- lua/config/autocmds.lua | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 lua/config/autocmds.lua (limited to 'lua/config/autocmds.lua') diff --git a/lua/config/autocmds.lua b/lua/config/autocmds.lua new file mode 100644 index 0000000..247f152 --- /dev/null +++ b/lua/config/autocmds.lua @@ -0,0 +1,83 @@ +local autocmd = vim.api.nvim_create_autocmd +local function augroup(name) + return vim.api.nvim_create_augroup("user_" .. name, { clear = true }) +end + +-- [[ Highlight on yank ]] +autocmd("TextYankPost", { + group = augroup("highlight_yank"), + callback = function() + vim.highlight.on_yank() + end, +}) + +-- [[ Auto create parent directory if it doesn't exist ]] +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, +}) + +-- Run gofmt + goimports on save +local format_sync_grp = vim.api.nvim_create_augroup("goimports", {}) +autocmd("BufWritePre", { + pattern = "*.go", + callback = function() + require("go.format").goimports() + end, + group = format_sync_grp, +}) + +autocmd("TermOpen", { + callback = function() + local o = vim.opt_local + o.signcolumn = "no" + o.number = false + o.relativenumber = false + vim.cmd("startinsert") + vim.keymap.set("t", "", "", { noremap = true }) + end, +}) +-- -- close automatically when shell process exits +-- -- TODO: does not work +-- autocmd("TermClose", { +-- callback = function() +-- vim.cmd("bdelete") +-- end, +-- }) +vim.keymap.set("n", "!", "spterm", { desc = "Open terminal" }) + +-- [[ preserve last position ]] +autocmd("BufReadPost", { + pattern = "*", + command = 'silent! normal! g`"zv', +}) + +-- [[ no cursorline in insert mode ]] +local cursorGrp = augroup("CursorLine") +autocmd({ "InsertLeave", "WinEnter" }, { + pattern = "*", + command = "set cursorline", + group = cursorGrp, + desc = "show cursor line only in active window", +}) +autocmd({ "InsertEnter", "WinLeave" }, { pattern = "*", command = "set nocursorline", group = cursorGrp }) + +-- [[ spellchecker activated in txt files ]] +autocmd( + { "BufRead", "BufNewFile" }, + -- { pattern = { "*.txt", "*.md", "*.tex" }, command = [[setlocal spell setlocal spelllang=en,de]] } + { + pattern = { "*.txt" }, + callback = function() + vim.opt.spell = true + vim.opt.spelllang = "en" + end, + desc = "Enable spell checking for certain file types", + } +) -- cgit v1.2.3