home: vim: numbertoggle: use lua callbacks

Use `vim.opt` because those are local options (i.e: similar to `set` it
defaults to setting it locally, `vim.opt_local` is not necessary).
This commit is contained in:
Bruno BELANYI 2024-07-15 20:40:37 +01:00
parent 280829b54f
commit a7c542784c

View file

@ -7,17 +7,28 @@ local numbertoggle = vim.api.nvim_create_augroup("numbertoggle", { clear = true
vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained", "InsertLeave", "WinEnter" }, {
pattern = "*",
group = numbertoggle,
command = "if &nu | setlocal rnu | endif",
callback = function()
if vim.opt.number:get() then
vim.opt.relativenumber = true
end
end,
})
vim.api.nvim_create_autocmd({ "BufLeave", "FocusLost", "InsertEnter", "WinLeave" }, {
pattern = "*",
group = numbertoggle,
command = "if &nu | setlocal nornu | endif",
callback = function()
if vim.opt.number:get() then
vim.opt.relativenumber = false
end
end,
})
-- Never show the sign column in a terminal buffer
vim.api.nvim_create_autocmd({ "TermOpen" }, {
pattern = "*",
group = numbertoggle,
command = "setlocal nonu nornu",
callback = function()
vim.opt.number = false
vim.opt.relativenumber = false
end,
})