Skip to content
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

Add cwd and vertical/horizontal keybindings to mini.files #2695

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dusty-phillips
Copy link
Contributor

@dusty-phillips dusty-phillips commented Mar 10, 2024

  • Makes the toggle_hidden keybinding configurable via mappings
  • Adds new mini.files keybindings for opening files in a vertical split, with both go_in and go_in_plus modes (configurable via mappings)
  • Adds new keybinding to change working directory from mini.files (configurable via mappings)

Closes #2692

@@ -32,7 +32,7 @@ return {
require("mini.files").setup(opts)

local show_dotfiles = true
local filter_show = function(fs_entry)
local filter_show = function(_)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stylelua was warning me about unused variable here.

@@ -45,12 +45,69 @@ return {
require("mini.files").refresh({ content = { filter = new_filter } })
end

local map_split = function(buf_id, lhs, direction, close_on_file)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is modified from the example in the mini.files repo quite a bit. notably, I made it open the selected file after creating the split, and added close_on_file so that we can have _plus keybindings. I also made the keybindings configurable via opts.mappings.

"n",
opts.mappings.toggle_hidden or "g.",
toggle_dotfiles,
{ buffer = buf_id, desc = "Toggle hidden files" }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added description here, though I also have a separate PR open for that in case you don't want to accept these more invasive changes.

vim.keymap.set("n", "g.", toggle_dotfiles, { buffer = buf_id })
vim.keymap.set(
"n",
opts.mappings.toggle_hidden or "g.",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added ability to configure this existing mapping from opts

map_split(buf_id, opts.mappings.go_in_horizontal or "gs", "horizontal", false)
map_split(buf_id, opts.mappings.go_in_vertical or "gv", "vertical", false)
map_split(buf_id, opts.mappings.go_in_horizontal_plus or "gS", "horizontal", true)
map_split(buf_id, opts.mappings.go_in_vertical_plus or "gV", "vertical", true)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first two mappings (as well as gc below) were suggested by mini.files documentation. I don't care for them as they conflict with existing mappings. Happy to change them to something more Lazy, but I'm not sure what they should be. Some ideas:

  • <space>| and <space><minus>, overwriting the LazyVim keymappings for opening new windows in splits, but not obvious what to do with the *_plus versions.
  • <C-w>v, <C-w>V, sandS`, overwriting the standard vim keymappings for opening new windows in splits.
  • \v, \V, \s, \S which is what I'll use because I have \ mapped to <C-w>

@pkazmier
Copy link
Contributor

pkazmier commented Mar 14, 2024

I'm very excited about these proposed enhancements for the mini.files extra. I've recently discovered mini.files, which has allowed me to completely disable neo-tree.

Re: which bindings to use, I'd vote for C-w v,V,s,S as pressing those bindings while in mini.files windows doesn't make sense and does weird stuff to the screen anyways, so might as well use them as they were intended :-) But, really, it doesn't matter too much as I generally launch mini.files in the window I want to open the file in anyways.

I'm just happy to have discovered it as it's so much faster using mini.files to navigate than a sidebar. I tried oil as well, but oil is much slower, and it's preview is ridiculously slow as it opens the whole file. Plus, mini gives you context.

@briandipalma
Copy link
Contributor

s is used to search. I would use it to move around quickly even in mini.files.

@dusty-phillips
Copy link
Contributor Author

dusty-phillips commented May 23, 2024

  • Rebased and fixed conflicts.
  • Switched to <ctrl-w>s and <ctrl-w>v for opening in splits

Tangentially related: my book recommends remapping \ to ctrl-w, and I suggest this could be a default in LazyVim. Then we don't need space-| and space- anymore because \v and \s are just as easy to type.

@folke is there anything you'd like me to do to get this into core and/or do you prefer not to have it merged so I can close it?

@dpetka2001
Copy link
Contributor

Kinda naive question, but is there a specific reason we use 2 separate autocmds on the same event?

@dusty-phillips
Copy link
Contributor Author

Kinda naive question, but is there a specific reason we use 2 separate autocmds on the same event?

It was cause in my local config I wanted to keep my changes separate from the LazyVim configuration, but since this IS the (proposed) LazyVim configuration it doesn't make sense here. I think I pulled a folke and pushed a change for it while you were asking the question. 😂

@dpetka2001
Copy link
Contributor

The last change you pushed actually reduced the number of autocmds from 3 to 2. There are still 2 separate autocmds, as far as I can see.

* Makes the toggle_hidden keybinding configurable via mappings
* Adds new mini.files keybindings for opening files
  in a vertical or horizontal split,
  with both go_in and go_in_plus modes
  (configurable via mappings)
* Adds new keybinding to change working directory
  from mini.files
  (configurable via mappings)
@dusty-phillips
Copy link
Contributor Author

I think that's just me being daft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: mini.files extra keymaps
4 participants