I'm converting my init.vim into a set of lua config files, called from init.lua I'm trying to convert this from init.vim
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
augroup END
to this in set.lua (loaded from init.lua)
local numtogGrp = vim.api.nvim_create_augroup("NumberToggle", { clear = true })
vim.api.nvim_create_autocmd(
{ "BufEnter", "InsertLeave", "FocusGained"},
{ pattern = "*",
--command = "set relativenumber", -- if callback, vim.api.nvim_buf_set_option(0,relativenumber,true) ?
callback = function()
vim.api.nvim_buf_set_option(0, 'relativenumber', true)
end,
group = numtogGrp,
desc = "Turn on relative line numbering when the buffer is entered.",
}
)
vim.api.nvim_create_autocmd(
{ "BufLeave", "InsertEnter", "FocusLost"},
{ pattern = "*",
--command = "set norelativenumber",
callback = function()
vim.api.nvim_buf_set_option(0, 'relativenumber', false)
end,
group = numtogGrp,
desc = "Turn off relative line numbering when the buffer is exited.",
}
)
No errors when I source the file, but when any of the events occur I get
'Invalid option name 'relativenumber'
Finally I realised I needed vim.api.nvim_set_option('relativenumber', true)
My question is, why is the option name not recognised by the buf_set_option
function?