1
0
Fork 0
mirror of https://github.com/pnx/dotfiles synced 2026-06-16 03:14:55 +02:00

new nvim config

This commit is contained in:
Henrik Hautakoski 2024-08-25 16:49:58 +02:00
parent f087422bbf
commit 7d14948480
66 changed files with 1771 additions and 1719 deletions

View file

@ -0,0 +1,58 @@
-- Helper functions for dealing with buffers
local M = {}
function M.Close(buf)
-- check if mini is installed.
local hasmini, mini = pcall(require,"mini.bufremove")
if hasmini then
local bd = mini.delete
if vim.bo[buf].modified then
local bufname = vim.fn.bufname(buf)
local choice = vim.fn.confirm(("Save changes to %q?"):format(bufname), "&Yes\n&No\n&Cancel")
if choice == 1 then -- Yes
vim.cmd(("%i,%ibufdo w"):format(buf, buf))
bd(buf)
elseif choice == 2 then -- No
bd(buf, true)
end
else
bd(buf)
end
-- fallback to native nvim api
else
vim.api.nvim_buf_delete(buf, {})
end
end
-- Close current buffer
function M.CloseCurrent()
M.Close(vim.api.nvim_get_current_buf())
end
-- Close all but current buffer
function M.CloseOthers()
for _, i in ipairs(vim.api.nvim_list_bufs()) do
if i ~= vim.api.nvim_get_current_buf() then
M.Close(i)
end
end
end
-- Close all open buffers
function M.CloseAll()
for _, i in ipairs(vim.api.nvim_list_bufs()) do
M.Close(i)
end
end
function M.GetLoaded()
local loaded = {}
for i, hnd in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_buf_is_loaded(hnd) then
loaded[i] = hnd
end
end
return loaded
end
return M