echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
4.45k stars 171 forks source link

When opening mini.files in a buffer deep into a project, I want mini.files to show that file. #981

Closed charlesbido closed 2 weeks ago

charlesbido commented 2 weeks ago

Contributing guidelines

Module(s)

mini.files

Description

Hey y'all 👋 first of all thank you to everyone who developed this module, it's by far my favorite file navigator in neovim ❤️

I'm running into the following issue (forgive the Gherkin, but its effective for describing the issue):

Given that I'm in a split pane view in neovim
And both panes have files located at different directories within the same project
And I'm in the first pane
When I move to the second pane
And I open mini.files
Then I'm at the last opened directory in mini.files, instead of the directory where the file in the second pane is located.

I want to be in the directory where the file in the second pane is located so that

I'm actually unsure if this is simply a bug, or would be considered a feature request (please let me know), but I think this behavior is typical in other file navigators such as Lf / Ranger / NERDTree and would address a lot of common use-cases.

Again many thanks!

Neovim version

NVIM v0.10.0

Steps to reproduce

  1. Open a large project in neovim
  2. Open a file in a directory
  3. Open a split pane
  4. Open another file in a different directory in the split pane
  5. Try switching between panes and opening mini.file to observe behavior

Expected behavior

When invoking Mini.files while on a pane (pane 1), it shows the file (file 1) at its location. Then when switching to another pane (pane 2) and invoking Mini.files, then it shows the file (file 2) at its location.

Actual behavior

It opens the last location navigated in mini.files

echasnovski commented 2 weeks ago

Hi! Glad you like 'mini.files'!

The MiniFiles.open() function takes arguments which can be used in different ways.

For described case it seems that using MiniFiles.open(vim.api.nvim_buf_get_name(0)) (which opens directory of current file in a last used state with focus on that file) instead of plain MiniFiles.open().

charlesbido commented 2 weeks ago

@echasnovski oh perfect! I should've checked the docs instead of just the README.md

I'll take a look and create bindings for this - also, thanks for the super fast response that was nearly instantaneous 🏎️ 🔥 wow

pkazmier commented 2 weeks ago

You might want to check to make sure buftype ~= "nofile" so you don't get an error if you use your mapping while in a buffer that doesn't have a real file associated with it. For example, if I use my mapping while on MiniStarter screen, the buftype is "nofile", but the buffer name looks like a path that is not a real file, so I'd get an error if I didn't add this check:

M.minifiles_open_buffer_path = function()
  local path = vim.bo.buftype ~= "nofile" and vim.api.nvim_buf_get_name(0) or nil
  MiniFiles.open(path)
end
charlesbido commented 2 weeks ago

@pkazmier This works well for my setup! Thanks for the recipe 😄