summaryrefslogtreecommitdiff
path: root/pkgs/old-custom-neovim/config/lua/plugins/mini/files.lua
diff options
context:
space:
mode:
authortriethyl <triethylammonium@pm.me>2025-08-16 20:20:21 -0400
committertriethyl <triethylammonium@pm.me>2025-08-16 20:20:21 -0400
commit58ceb817bb6ba195d1189160878f318f3bcda0ef (patch)
tree6c17c013c92af8c6e410bb1d4fe3a2557841d0d3 /pkgs/old-custom-neovim/config/lua/plugins/mini/files.lua
parent94980b0be13a690128992d98a2ed5db3ab592642 (diff)
neovim: restarted config
Diffstat (limited to 'pkgs/old-custom-neovim/config/lua/plugins/mini/files.lua')
-rw-r--r--pkgs/old-custom-neovim/config/lua/plugins/mini/files.lua91
1 files changed, 91 insertions, 0 deletions
diff --git a/pkgs/old-custom-neovim/config/lua/plugins/mini/files.lua b/pkgs/old-custom-neovim/config/lua/plugins/mini/files.lua
new file mode 100644
index 0000000..1dc1c3e
--- /dev/null
+++ b/pkgs/old-custom-neovim/config/lua/plugins/mini/files.lua
@@ -0,0 +1,91 @@
+require("mini.files").setup {
+ mappings = {
+ close = '<esc>',
+ go_in = 'L',
+ go_in_plus = "<cr>",
+ go_out = 'H',
+ go_out_plus = '<c-h>',
+ mark_goto = "'",
+ mark_set = 'm',
+ reset = '<bs>',
+ reveal_cwd = '@',
+ show_help = 'g?',
+ synchronize = '=',
+ trim_left = '<',
+ trim_right = '>',
+ },
+ windows = {
+ preview = true,
+ },
+}
+
+-- Set focused directory as current working directory
+local set_cwd = function()
+ local path = (MiniFiles.get_fs_entry() or {}).path
+ if path == nil then return vim.notify('Cursor is not on valid entry') end
+ vim.fn.chdir(vim.fs.dirname(path))
+end
+
+-- Yank in register full path of entry under cursor
+local yank_path = function()
+ local path = (MiniFiles.get_fs_entry() or {}).path
+ if path == nil then return vim.notify('Cursor is not on valid entry') end
+ vim.fn.setreg(vim.v.register, path)
+end
+
+-- Open path with system default handler (useful for non-text files)
+local ui_open = function() vim.ui.open(MiniFiles.get_fs_entry().path) end
+
+vim.api.nvim_create_autocmd('User', {
+ pattern = 'MiniFilesBufferCreate',
+ callback = function(args)
+ local b = args.data.buf_id
+ vim.keymap.set('n', 'g~', set_cwd, { buffer = b, desc = 'Set cwd' })
+ vim.keymap.set('n', 'gX', ui_open, { buffer = b, desc = 'OS open' })
+ vim.keymap.set('n', 'gy', yank_path, { buffer = b, desc = 'Yank path' })
+ end,
+})
+
+-- Add custom bookmarks.
+local set_mark = function(id, path, desc)
+ MiniFiles.set_bookmark(id, path, { desc = desc })
+end
+
+vim.api.nvim_create_autocmd('User', {
+ pattern = 'MiniFilesExplorerOpen',
+ callback = function()
+ set_mark('w', vim.fn.getcwd, 'Working directory') -- callable
+ set_mark('~', '~', 'Home directory')
+ end,
+})
+
+-- Add split keys
+local map_split = function(buf_id, lhs, direction)
+ local rhs = function()
+ -- Make new window and set it as target
+ local cur_target = MiniFiles.get_explorer_state().target_window
+ local new_target = vim.api.nvim_win_call(cur_target, function()
+ vim.cmd(direction .. ' split')
+ return vim.api.nvim_get_current_win()
+ end)
+
+ MiniFiles.set_target_window(new_target)
+
+ MiniFiles.go_in()
+ 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 buf_id = args.data.buf_id
+ -- Tweak keys to your liking
+ map_split(buf_id, '<C-s>', 'belowright horizontal')
+ map_split(buf_id, '<C-v>', 'belowright vertical')
+ map_split(buf_id, '<C-t>', 'tab')
+ end,
+})