From b8481dcb1a11e26c641bdac207eacfecde8b86bd Mon Sep 17 00:00:00 2001 From: Tigor Hutasuhut Date: Thu, 7 Nov 2024 20:37:22 +0700 Subject: [PATCH] mini_files: added integration with snacks --- lua/plugins/mini_files.lua | 115 +++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 51 deletions(-) diff --git a/lua/plugins/mini_files.lua b/lua/plugins/mini_files.lua index b255aad..be9d17e 100644 --- a/lua/plugins/mini_files.lua +++ b/lua/plugins/mini_files.lua @@ -1,56 +1,69 @@ return { - "echasnovski/mini.nvim", - version = false, - enabled = true, - opts = { - windows = { - preview = true, - width_preview = 50, + { + "echasnovski/mini.nvim", + version = false, + enabled = true, + opts = { + windows = { + preview = true, + width_preview = 50, + }, + }, + config = function(_, opts) + require("mini.files").setup(opts) + local map_split = function(buf_id, lhs, direction) + local mf = require "mini.files" + local rhs = function() + -- Make new window and set it as target + local new_target_window + vim.api.nvim_win_call(mf.get_target_window(), function() + vim.cmd(direction .. " split") + new_target_window = vim.api.nvim_get_current_win() + end) + + mf.set_target_window(new_target_window) + end + + -- Adding `desc` will result into `show_help` entries + local desc = "Split " .. direction + vim.keymap.set("n", lhs, rhs, { buffer = buf_id, desc = desc }) + end + vim.api.nvim_create_autocmd("User", { + pattern = "MiniFilesBufferCreate", + callback = function(args) + local mf = require "mini.files" + local buf_id = args.data.buf_id + -- Tweak keys to your liking + map_split(buf_id, "gs", "belowright horizontal") + map_split(buf_id, "gv", "belowright vertical") + vim.keymap.set("n", "", function() + mf.go_in { close_on_file = true } + end, { buffer = buf_id, desc = "Open file or directory" }) + end, + }) + end, + keys = { + { + "-", + function() + local mf = require "mini.files" + if not mf.close() then + mf.open(vim.api.nvim_buf_get_name(0), false) + end + end, + desc = "Open/Close mini files from current file directory", + }, }, }, - config = function(_, opts) - require("mini.files").setup(opts) - local map_split = function(buf_id, lhs, direction) - local mf = require "mini.files" - local rhs = function() - -- Make new window and set it as target - local new_target_window - vim.api.nvim_win_call(mf.get_target_window(), function() - vim.cmd(direction .. " split") - new_target_window = vim.api.nvim_get_current_win() - end) - - mf.set_target_window(new_target_window) - end - - -- Adding `desc` will result into `show_help` entries - local desc = "Split " .. direction - vim.keymap.set("n", lhs, rhs, { buffer = buf_id, desc = desc }) - end - vim.api.nvim_create_autocmd("User", { - pattern = "MiniFilesBufferCreate", - callback = function(args) - local mf = require "mini.files" - local buf_id = args.data.buf_id - -- Tweak keys to your liking - map_split(buf_id, "gs", "belowright horizontal") - map_split(buf_id, "gv", "belowright vertical") - vim.keymap.set("n", "", function() - mf.go_in { close_on_file = true } - end, { buffer = buf_id, desc = "Open file or directory" }) - end, - }) - end, - keys = { - { - "-", - function() - local mf = require "mini.files" - if not mf.close() then - mf.open(vim.api.nvim_buf_get_name(0), false) - end - end, - desc = "Open/Close mini files from current file directory", - }, + { + "folke/snacks.nvim", + init = function() + vim.api.nvim_create_autocmd("User", { + pattern = "MiniFilesActionRename", + callback = function(event) + Snacks.rename.on_rename_file(event.data.from, event.data.to) + end, + }) + end, }, }