home: vim: numbertoggle: use lua autocommands

A nice next step would be to use actual lua callbacks instead of the
VimL command.
This commit is contained in:
Bruno BELANYI 2023-05-06 18:17:16 +01:00
parent 36b0c67832
commit dba8836381

View file

@ -1,13 +1,25 @@
" Idea for toggling taken from jeffkreeftmeijer lua << EOF
-- Show lines numbers
vim.opt.number = true
" Show line numbers local numbertoggle = vim.api.nvim_create_augroup("numbertoggle", { clear = true })
set number
augroup numbertoggle -- Toggle numbers between relative and absolute when changing buffers
autocmd! vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained", "InsertLeave", "WinEnter" }, {
" Toggle numbers between relative and absolute when changing buffers pattern = "*",
autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu | set rnu | endif group = numbertoggle,
autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif command = "if &nu | setlocal rnu | endif",
" Disable line numbers and relative line numbers in terminal })
autocmd TermOpen * setlocal nonu nornu vim.api.nvim_create_autocmd({ "BufLeave", "FocusLost", "InsertEnter", "WinLeave" }, {
augroup END pattern = "*",
group = numbertoggle,
command = "if &nu | setlocal nornu | endif",
})
-- Never show the sign column in a terminal buffer
vim.api.nvim_create_autocmd({ "TermOpen" }, {
pattern = "*",
group = numbertoggle,
command = "setlocal nonu nornu",
})
EOF