diff --git a/init.lua b/init.lua index a4e7902..1b01f11 100644 --- a/init.lua +++ b/init.lua @@ -83,11 +83,11 @@ I hope you enjoy your Neovim journey, P.S. You can delete this when you're done too. It's your config now! :) --]] -vim.o.guifont = 'SauceCodePro NF:h12' +vim.o.guifont = 'AdwaitaMono Nerd Font:h12' vim.o.autochdir = true -vim.o.softtabstop = 2 -vim.o.shiftwidth = 2 +vim.o.softtabstop = 4 +vim.o.shiftwidth = 4 -- Set as the leader key -- See `:help mapleader` @@ -108,6 +108,34 @@ vim.o.number = true -- You can also add relative line numbers, to help with jumping. -- Experiment for yourself to see if you like it! -- vim.o.relativenumber = true +-- + +local augroup = vim.api.nvim_create_augroup('numbertoggle', {}) + +vim.api.nvim_create_autocmd({ 'BufEnter', 'FocusGained', 'InsertLeave', 'CmdlineLeave', 'WinEnter' }, { + pattern = '*', + group = augroup, + callback = function() + if vim.o.nu and vim.api.nvim_get_mode().mode ~= 'i' then + vim.opt.relativenumber = true + end + end, +}) + +vim.api.nvim_create_autocmd({ 'BufLeave', 'FocusLost', 'InsertEnter', 'CmdlineEnter', 'WinLeave' }, { + pattern = '*', + group = augroup, + callback = function() + if vim.o.nu then + vim.opt.relativenumber = false + -- Conditional taken from https://github.com/rockyzhang24/dotfiles/commit/03dd14b5d43f812661b88c4660c03d714132abcf + -- Workaround for https://github.com/neovim/neovim/issues/32068 + if not vim.tbl_contains({ '@', '-' }, vim.v.event.cmdtype) then + vim.cmd 'redraw' + end + end + end, +}) -- Enable mouse mode, can be useful for resizing splits for example! vim.o.mouse = 'a'