-
Notifications
You must be signed in to change notification settings - Fork 933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: mini.files extra keymaps #2692
Labels
enhancement
New feature or request
Comments
For reference, here is the config that I used to override the default one provided by lazvim (as far as I can tell, there's no way to say "call the default config" from inside the config call so I have to completely overwrite it? (collapsed because I have a PR with a better version of this) config = function(_, opts)
require("mini.files").setup(opts)
local show_dotfiles = true
local filter_show = function(fs_entry)
return true
end
local filter_hide = function(fs_entry)
return not vim.startswith(fs_entry.name, ".")
end
local toggle_dotfiles = function()
show_dotfiles = not show_dotfiles
local new_filter = show_dotfiles and filter_show or filter_hide
require("mini.files").refresh({ content = { filter = new_filter } })
end
local map_split = function(buf_id, lhs, direction)
local rhs = function()
-- Make new window and set it as target
local new_target_window
local cur_target_window = require("mini.files").get_target_window()
if cur_target_window ~= nil then
vim.api.nvim_win_call(cur_target_window, function()
vim.cmd(direction .. " split")
new_target_window = vim.api.nvim_get_current_win()
end)
require("mini.files").set_target_window(new_target_window)
require("mini.files").go_in({ close_on_file = true })
end
end
local desc = "Split " .. direction
vim.keymap.set("n", lhs, rhs, { buffer = buf_id, desc = desc })
end
local files_set_cwd = function()
local cur_entry_path = MiniFiles.get_fs_entry().path
local cur_directory = vim.fs.dirname(cur_entry_path)
if cur_directory ~= nil then
vim.fn.chdir(cur_directory)
end
end
vim.api.nvim_create_autocmd("User", {
pattern = "MiniFilesBufferCreate",
callback = function(args)
local buf_id = args.data.buf_id
vim.keymap.set("n", "g.", toggle_dotfiles, { buffer = buf_id, desc = "Toggle dotfiles" })
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, "gs", "belowright horizontal")
map_split(buf_id, "gv", "belowright vertical")
end,
})
vim.api.nvim_create_autocmd("User", {
pattern = "MiniFilesBufferCreate",
callback = function(args)
vim.keymap.set("n", "gc", files_set_cwd, { buffer = args.data.buf_id, desc = "Set cwd" })
end,
})
vim.api.nvim_create_autocmd("User", {
pattern = "MiniFilesActionRename",
callback = function(event)
require("lazyvim.util").lsp.on_rename(event.data.from, event.data.to)
end,
})
end, Some notes:
|
Created the linked PR to implement all of the above, though I'm cautious about the keybindings. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you check the docs?
Is your feature request related to a problem? Please describe.
I prefer mini.files to neotree and have disabled neotree. Two actions I would like to invoke on my filesystem are not possible in the default mini.files extra: splitting windows and changing CWD.
Describe the solution you'd like
Mini.files provides documentation for mapping splits and setting cwd here:
https://github.com/echasnovski/mini.nvim/blob/e578f353d0b1d9f21a9640458d8e506c0c9acf5e/doc/mini-files.txt#L429
I would like LazyVim-sensible keybindings for these actions. Ideally, it would be possible to configure the keybindings without overriding
config()
.Describe alternatives you've considered
I can, of course, extend the existing LazyVim config to include these mini.files keymaps, but I felt they would be useful for other users as well.
Additional context
No response
The text was updated successfully, but these errors were encountered: