Rename and refactor nvim ephemeral plugin
This commit is contained in:
parent
c1d76da6ac
commit
32d840e7b1
2 changed files with 36 additions and 17 deletions
|
@ -1,17 +0,0 @@
|
|||
vim.api.nvim_create_user_command("BHD", function()
|
||||
vim.bo.bufhidden = "delete"
|
||||
end, {})
|
||||
|
||||
vim.api.nvim_create_user_command("BHK", function()
|
||||
vim.bo.bufhidden = nil
|
||||
end, {})
|
||||
|
||||
vim.g.ephemeral_buffers = false
|
||||
|
||||
vim.api.nvim_create_autocmd("BufAdd", {
|
||||
callback = function(args)
|
||||
if vim.g.ephemeral_buffers then
|
||||
vim.bo[args.buf].bufhidden = "delete"
|
||||
end
|
||||
end
|
||||
})
|
36
vim/plugin/ephemeral.lua
Normal file
36
vim/plugin/ephemeral.lua
Normal file
|
@ -0,0 +1,36 @@
|
|||
vim.api.nvim_create_user_command("Pin", function()
|
||||
vim.bo.bufhidden = "delete"
|
||||
end, {})
|
||||
|
||||
vim.api.nvim_create_user_command("Drop", function()
|
||||
vim.bo.bufhidden = nil
|
||||
end, {})
|
||||
|
||||
vim.api.nvim_create_user_command("Ephemeral", function(params)
|
||||
if params.args == "" then
|
||||
print(vim.g.ephemeral_buffers
|
||||
and "New buffers are ephemeral"
|
||||
or "New buffers are permanent"
|
||||
)
|
||||
elseif params.args == "on" then
|
||||
vim.g.ephemeral_buffers = true
|
||||
elseif params.args == "off" then
|
||||
vim.g.ephemeral_buffers = false
|
||||
else
|
||||
vim.api.nvim_echo({{"Unknown option: "}, {params.args, "error"}}, false, {})
|
||||
end
|
||||
end, {nargs = "?", complete = function(lead)
|
||||
return vim.fn.filter({ "on", "off" }, function(_, val)
|
||||
return val:find("^" .. lead)
|
||||
end)
|
||||
end})
|
||||
|
||||
vim.g.ephemeral_buffers = false
|
||||
|
||||
vim.api.nvim_create_autocmd("BufAdd", {
|
||||
callback = function(args)
|
||||
if vim.g.ephemeral_buffers then
|
||||
vim.bo[args.buf].bufhidden = "delete"
|
||||
end
|
||||
end
|
||||
})
|
Loading…
Reference in a new issue