From 09920fde9bfba712ee1a21311449641215c1d1eb Mon Sep 17 00:00:00 2001 From: Kirk Easterson Date: Thu, 12 Sep 2024 12:10:56 +0200 Subject: [PATCH] feat(nvim): create autocmds for setting relative linenumbers --- nvim/.config/nvim/lua/kirk/core/autocmds.lua | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/nvim/.config/nvim/lua/kirk/core/autocmds.lua b/nvim/.config/nvim/lua/kirk/core/autocmds.lua index 846b49eb..167575fb 100644 --- a/nvim/.config/nvim/lua/kirk/core/autocmds.lua +++ b/nvim/.config/nvim/lua/kirk/core/autocmds.lua @@ -207,3 +207,24 @@ autocmd("BufWritePost", { end, once = false, }) + +local num_toggle_autgroup = augroup("numbertoggle", {}) +autocmd({ "BufEnter", "FocusGained", "WinEnter" }, { + pattern = "*", + group = num_toggle_autgroup, + callback = function() + if vim.o.nu then + vim.opt.relativenumber = true + end + end, +}) + +autocmd({ "BufLeave", "FocusLost", "WinLeave" }, { + pattern = "*", + group = num_toggle_autgroup, + callback = function() + if vim.o.nu then + vim.opt.relativenumber = false + end + end, +})