Vimscript to lua for an autocommand

The folloing autocmd disables tabline and statusline in alpha.nvim:

vim.cmd([[
  augroup _alpha
    autocmd!
    autocmd User AlphaReady set showtabline=0 | autocmd BufUnload <buffer> set showtabline=2
    autocmd User AlphaReady set laststatus=0 | autocmd BufUnload <buffer> set laststatus=2
  augroup end
]])

What would be equivalent with nvim_create_autocmd?


P.S. - I tried

local _alpha = augr("_alpha", { clear = true })
aucmd("User", {
  pattern = "AlphaReady",
  callback = function()
    vim.opt.showtabline = 0
    vim.opt.laststatus = 0
  end,
  group = _alpha,
})
aucmd("BufUnload", {
  buffer = 0,
  callback = function()
    vim.opt.showtabline = 2
    vim.opt.laststatus = 2
  end,
  group = _alpha,
})

But the 2nd aucmd does not work as intended … i.e., statusline and tabline do not reappear when a file buffer is reloaded.

It should be

local _alpha = augr("_alpha", { clear = true })
aucmd("User", {
  pattern = "AlphaReady",
  callback = function()
    vim.opt.showtabline = 0
    vim.opt.laststatus = 0
    aucmd("BufUnload", {
      buffer = 0,
      callback = function()
        vim.opt.showtabline = 2
        vim.opt.laststatus = 2
      end,
      group = _alpha,
    })
  end,
  group = _alpha,
})
1 Like

It works. Thanks a lot :slight_smile: