feat(nvim): minify copnfig
This commit is contained in:
parent
772322333c
commit
58703c4bf8
4 changed files with 79 additions and 38 deletions
40
config/nvim/plugin/bufremove.lua
Normal file
40
config/nvim/plugin/bufremove.lua
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
-- https://github.com/echasnovski/mini.bufremove/blob/main/lua/mini/bufremove.lua#L86
|
||||
|
||||
---@param wipeout? boolean
|
||||
local function bufremove(wipeout)
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
local cmd = wipeout and 'bwipeout' or 'bdelete'
|
||||
|
||||
if vim.bo[buf].modified then
|
||||
local ok = vim.fn.confirm(
|
||||
('Buffer %d has unsaved changes. Force %s?'):format(buf, cmd),
|
||||
'&No\n&Yes', 1, 'Question'
|
||||
) == 2
|
||||
if not ok then return end
|
||||
end
|
||||
|
||||
for _, win in ipairs(vim.fn.win_findbuf(buf)) do
|
||||
vim.api.nvim_win_call(win, function()
|
||||
if vim.fn.getcmdwintype() ~= '' then
|
||||
vim.cmd('close!')
|
||||
return
|
||||
end
|
||||
local alt = vim.fn.bufnr('#')
|
||||
if alt ~= buf and vim.fn.buflisted(alt) == 1 then
|
||||
vim.api.nvim_win_set_buf(win, alt)
|
||||
elseif pcall(vim.cmd, 'bprevious') and buf ~= vim.api.nvim_win_get_buf(win) then
|
||||
return
|
||||
else
|
||||
vim.api.nvim_win_set_buf(win, vim.api.nvim_create_buf(true, false))
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local ok, err = pcall(vim.cmd, ('%s! %d'):format(cmd, buf))
|
||||
if not ok and not (err:find('E516%D') or err:find('E517%D') or err:find('E11%D')) then
|
||||
vim.notify(err, vim.log.levels.ERROR)
|
||||
end
|
||||
end
|
||||
|
||||
vim.keymap.set('n', '<leader>bd', function() bufremove() end)
|
||||
vim.keymap.set('n', '<leader>bw', function() bufremove(true) end)
|
||||
39
config/nvim/plugin/zoom.lua
Normal file
39
config/nvim/plugin/zoom.lua
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
-- https://github.com/echasnovski/mini.misc/blob/main/lua/mini/misc.lua#L838
|
||||
|
||||
---@type integer?
|
||||
local zoom_winid = nil
|
||||
|
||||
local function zoom()
|
||||
if zoom_winid and vim.api.nvim_win_is_valid(zoom_winid) then
|
||||
vim.api.nvim_win_close(zoom_winid, true)
|
||||
zoom_winid = nil
|
||||
return
|
||||
end
|
||||
local cfg = {
|
||||
relative = 'editor',
|
||||
row = 0,
|
||||
col = 0,
|
||||
width = vim.o.columns,
|
||||
height = vim.o.lines - vim.o.cmdheight,
|
||||
border = 'none',
|
||||
}
|
||||
zoom_winid = vim.api.nvim_open_win(0, true, cfg)
|
||||
vim.cmd.normal('zz', { bang = true })
|
||||
vim.api.nvim_create_autocmd('VimResized', {
|
||||
group = vim.api.nvim_create_augroup('Zoom', { clear = true }),
|
||||
callback = function()
|
||||
if not (zoom_winid and vim.api.nvim_win_is_valid(zoom_winid)) then
|
||||
return
|
||||
end
|
||||
vim.api.nvim_win_set_config(zoom_winid, {
|
||||
relative = 'editor',
|
||||
row = 0,
|
||||
col = 0,
|
||||
width = vim.o.columns,
|
||||
height = vim.o.lines - vim.o.cmdheight,
|
||||
})
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
vim.keymap.set('n', '<c-w>m', zoom)
|
||||
Loading…
Add table
Add a link
Reference in a new issue