Would this work?
If Preserve
has a 100% chance of being defined:
vim.api.nvim_create_user_command('BufOnly',function()
pcall(vim.fn.Preserve("exec '%bd|e#|bd#'"))
end,{})
If Preserve
may not be defined:
vim.api.nvim_create_user_command('BufOnly',function()
pcall(function()
vim.fn.Preserve("exec '%bd|e#|bd#'")
end)
end,{})