diff --git a/config/nvim/lua/plugins/nvim.lua b/config/nvim/lua/plugins/nvim.lua index 324c374..690925d 100644 --- a/config/nvim/lua/plugins/nvim.lua +++ b/config/nvim/lua/plugins/nvim.lua @@ -3,8 +3,6 @@ vim.pack.add({ 'https://github.com/monaqa/dial.nvim', 'https://github.com/catgoose/nvim-colorizer.lua', 'https://github.com/echasnovski/mini.pairs', - 'https://github.com/echasnovski/mini.misc', - 'https://github.com/nvim-mini/mini.bufremove', 'https://github.com/tpope/vim-abolish', 'https://github.com/tpope/vim-sleuth', 'https://github.com/kylechui/nvim-surround', @@ -202,34 +200,6 @@ return { end, event = 'BufReadPre', }, - { - 'echasnovski/mini.misc', - after = function() - require('mini.misc').setup() - end, - keys = { - { - 'm', - "lua MiniMisc.zoom(0, { title = '', border = 'none' })", - }, - }, - }, - { - 'nvim-mini/mini.bufremove', - after = function() - require('mini.bufremove').setup() - end, - keys = { - { - 'bd', - 'lua MiniBufremove.delete()', - }, - { - 'bw', - 'lua MiniBufremove.wipeout()', - }, - }, - }, { 'tpope/vim-abolish', event = 'DeferredUIEnter' }, { 'tpope/vim-sleuth', event = 'BufReadPost' }, { diff --git a/config/nvim/nvim-pack-lock.json b/config/nvim/nvim-pack-lock.json index 3a742f3..d3d014a 100644 --- a/config/nvim/nvim-pack-lock.json +++ b/config/nvim/nvim-pack-lock.json @@ -60,14 +60,6 @@ "rev": "4b0a6207341d895b6cfe9bcb1e4d3e8607bfe4f4", "src": "https://github.com/echasnovski/mini.ai" }, - "mini.bufremove": { - "rev": "ee69f823f84508c556127a5882760d9783692023", - "src": "https://github.com/nvim-mini/mini.bufremove" - }, - "mini.misc": { - "rev": "de8947231c29012271722651aa07f6749c41d1ed", - "src": "https://github.com/echasnovski/mini.misc" - }, "mini.pairs": { "rev": "b7fde3719340946feb75017ef9d75edebdeb0566", "src": "https://github.com/echasnovski/mini.pairs" diff --git a/config/nvim/plugin/bufremove.lua b/config/nvim/plugin/bufremove.lua new file mode 100644 index 0000000..7770ae1 --- /dev/null +++ b/config/nvim/plugin/bufremove.lua @@ -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', 'bd', function() bufremove() end) +vim.keymap.set('n', 'bw', function() bufremove(true) end) diff --git a/config/nvim/plugin/zoom.lua b/config/nvim/plugin/zoom.lua new file mode 100644 index 0000000..8c94a06 --- /dev/null +++ b/config/nvim/plugin/zoom.lua @@ -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', 'm', zoom)