summaryrefslogtreecommitdiff
path: root/pkgs/custom-neovim/config/lua/autocommands.lua
diff options
context:
space:
mode:
authortriethyl <triethylammonium@pm.me>2025-07-06 22:21:45 -0400
committertriethyl <triethylammonium@pm.me>2025-07-06 22:21:45 -0400
commit546752feb6576be92fe421be1998217aa7d657ff (patch)
tree4ac774569cdbbffa6720b85a8130ea1e23529cf3 /pkgs/custom-neovim/config/lua/autocommands.lua
parent3df44ee18a6c1b36278cbde8499f357e0a040411 (diff)
working on nvim setup
Former-commit-id: a43ab0499838d262445d8af9cb954a84e259bb35
Diffstat (limited to 'pkgs/custom-neovim/config/lua/autocommands.lua')
-rw-r--r--pkgs/custom-neovim/config/lua/autocommands.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/pkgs/custom-neovim/config/lua/autocommands.lua b/pkgs/custom-neovim/config/lua/autocommands.lua
index e69de29..85a58c6 100644
--- a/pkgs/custom-neovim/config/lua/autocommands.lua
+++ b/pkgs/custom-neovim/config/lua/autocommands.lua
@@ -0,0 +1,36 @@
+-- Autocommands
+
+-- Use relative line number in normal mode and absolute in insert mode
+vim.opt.number = true
+local numbertoggle = vim.api.nvim_create_augroup("numbertoggle", {})
+vim.api.nvim_create_autocmd(
+ { "BufEnter", "FocusGained", "InsertLeave", "WinEnter", "CmdlineLeave" },
+ {
+ group = numbertoggle,
+ callback = function()
+ if vim.opt.number and vim.api.nvim_get_mode() ~= "i" then
+ vim.opt.relativenumber = true
+ end
+ end,
+ }
+)
+
+vim.api.nvim_create_autocmd(
+ { "BufLeave", "FocusLost", "InsertEnter", "WinLeave", "CmdlineEnter" },
+ {
+ group = numbertoggle,
+ callback = function()
+ if vim.opt.number then
+ vim.opt.relativenumber = false
+ vim.cmd("redraw")
+ end
+ end,
+ }
+)
+
+ -- start terminal in insert mode
+vim.api.nvim_create_autocmd("TermOpen", {
+ callback = function()
+ vim.cmd "startinsert!"
+ end,
+})