nvim-tree / nvim-tree.lua

A file explorer tree for neovim written in lua
Other
7.22k stars 610 forks source link

Navigate tree using fuzzy search #2251

Open eyalk11 opened 1 year ago

eyalk11 commented 1 year ago

When you have multiple dirs, you can reach your destination much faster using the following method ( I implemented it in my config for vim-netranger plugin so I know :) ) :

It will look something like that. You press key to start fuzzy-search* files in current directory. As you type it will display only the files/directories that match the search. You should have mappings that either->

  1. set as root your current selection and start fuzzy search in this directory .
  2. go back to previous fuzzy search
  3. open the file of course (optionally expanding all subtree could be nice too).

I didn't check the api , but I know I don't want to implement this myself again as this is tricky.

PS I might be able to upload a gif.

*(non-fuzzy is possible but a bit lame)

gegoune commented 1 year ago

Most of it should be possible using filters and current api. Give it a go and if some functionality is missing it will be easier to ask for specific api rather than targeted functionalities.

eyalk11 commented 1 year ago

I see two (alternative) needed functionalities that I can work with:

  1. (preferred) Don't create a vim buffer in insert mode for filtering text , but rather just display typed text and have the user still able to select files /folders . This is in any case significant improvement to the filtering mechanism IMO.

You can see related NETRSearch functions here:

https://github.com/ipod825/vim-netranger/blob/83cf4d112397ba841ddcafaed854c56681d82397/pythonx/netranger/netranger.py#L2018

The trick here is to call input("/") . Using timer, to update matches based on getcmdline() .

That is probably the same thing as https://github.com/lambdalisue/fin.vim which could actually be used to filter nvim-tree.

  1. Add to the api ability to provide a positive filtering function that would be evaluated on demand.

PS. I can implement it myself using a fork of Fin, but then no one will use it. I can create a PR and have it by default, but there will be a dependency of my fork of Fin. What I am going to do there is to call lua function that evaluates if it was started by nvim-tree and then go to the right folder and start fuzzy again. So it is a bit patchy. Is it acceptable?

alex-courtis commented 1 year ago

It sounds like some additional functionality would be required, ideally via API additions.

Adding a dependency on an forked / not actively supported plugin is not acceptable. Using a widely library/plugin like plenary would be acceptable, however implementing the functionality in nvim-tree is preferred.

We're open to pull requests and additions. Before creating a PR it would be useful to:

alex-courtis commented 1 year ago

My workflow for such case is to use telescope for find files and live grep. Something like:

telescope.live_grep({ search_dirs = ... })

I'm using commands to do that however now that you have given me the idea I'll implement nvim-tree mappings ;)

alex-courtis commented 1 year ago

Many thanks... now I have f and g https://github.com/alex-courtis/arch/blob/39a1ba4ecc3d356bb660a489d3648b987ecd9a85/config/nvim/lua/amc/plugins/nvt.lua#L20

eyalk11 commented 1 year ago

Didn't work for me. I probably have a problem with live_grep. Will try to fix it. Also I am not in favor of this approach.

"Adding a dependency on an forked / not actively supported plugin is not acceptable"

I am inclined not to invest a lot on this. So the least effort method is with the plugin and it is already half working. Also, I think it is the best way. Why rewriting something that works already? It works great.

myrec3

However, since I want people to use it, maybe I will decide to implement it in a more orthodox way.

"Add to the api ability to provide a positive filtering function that would be evaluated on demand."

Are you open to adding it? It seems fairly simple but I might get into avenues I don't want to. Especially as I never really programmed in lua , and chatgpt does too much mistakes :)

The code btw:

    vim.keymap.set('n', '/',(function() vim.api.nvim_command('Fin -matcher=fuzzy') end) , opts('Find'))

The current implementation I am thinking about is to allow to pass two functions into Fin, one is step into the tree and one out. The keys could be set as globals. The functions will be implemented in lua.

(It now has function of accept).

A design without it, will require to set active filtering mode(everything in grey?), get input from cmdline, every timer take the input, run a fuzzer through the list of folders/files, send it to the positive filtering function that will update the input , and implement the two functions that we already need to implement in the Fin method. In terms of maintaining, it will be harder.

alex-courtis commented 1 year ago
  • I don't mind forking and supporting it. It is a very simple functionality that haven't changed for 10 years. Some code doesn't need maintenance. Don't forget it is an optional feature.

Ah yes, my apologies, optional would be great. There are already a couple of extension plugins

Are you open to adding it? It seems fairly simple but I might get into avenues I don't want to. Especially as I never really programmed in lua , and chatgpt does too much mistakes :)

We're always very happy to accept contributions: wiki: Development. I'm happy to provide some guidance on a PR.

eyalk11 commented 1 year ago

Yeh, cool. (sorry, didn't see your answer for a long time). So, I will work on it some time. It will probably be a dedicated plugin . The interaction with nvim-tree is not clear, maybe I won't need an api. I might send some questions here (if there is no discord or anything).

alex-courtis commented 1 year ago

Yeh, cool. (sorry, didn't see your answer for a long time). So, I will work on it some time.

Your work will be gratefully appreciated.

I might send some questions here (if there is no discord or anything).

Discussions in issues are preferable: they are durable and easily found.

The interaction with nvim-tree is not clear, maybe I won't need an api.

We're always happy to add API as needed; we don't want plugins / extensions using private/internal functions.