nvim-tree/nvim-tree.lua

Persist the "filter options" over the session lifecycle

Opened this issue · 2 comments

hey nvim-tree builders,

I would like to raise a small feature request to you, which may increase the nvim-tree UX a bit, just for your reference. Thanks a lot for building this useful tool.

Is this a question?
No

Can this functionality be implemented utilising API?
I'm not very sure about this, but with a preliminary search in the API, I didn't find a very straight-forward way to implement it.

Is your feature request related to a problem? Please describe.

I set the nvim-tree to update root dir following the buffer switch, I often switch back and forth between two git projects which have different root ofc. The default setting recognizes .gitignore, so, in a project, if I need to inspect some git ignored files, I have to turn off the ignore filter by I key, navigate to the ignored directory and open the target file. But quickly, I ran into two problems:

  • When I switch to another file in a different root dir, then switch back later, I expected the tree view is exactly the same as I left it, i.e. a view showing all ignore dirs/files are still there and focus follows my opened file, it means my previous filter toggle is still functioning. However, they are all gone, i have to toggle ignore filter again to show those ignored files.
  • After I toggle ignore filter again, the tree-view didn't refresh to follow the opened file automatically, I have to navigate to the deep dir which contains that file...
      update_focused_file = {
        enable = true,
        update_root = {
          enable = true,
          ignore_list = {},
        },
        exclude = false,
      },

Describe the solution you'd like

  • The filter options can persist across root dir switchs, and be a session level setting.
  • Once set, it can apply on all the root dirs you switch to.
  • The tree focus can follow the files on the ignore list, only if you turn off the ignore filter for current session.
  • The setting doesn't change the default settings, in a new vim session, all the filter option changes are gone.
  • The filter options can persist across root dir switchs, and be a session level setting.
  • Once set, it can apply on all the root dirs you switch to.
  • The tree focus can follow the files on the ignore list, only if you turn off the ignore filter for current session.
  • The setting doesn't change the default settings, in a new vim session, all the filter option changes are gone.

That is achievable. On a root directory change the existing Explorer instance is destroyed and a new one created. Some state could be passed in just that case.

Please note that #2255 is a work in progress, allowing many instances each with their own state. This change will not be an issue as we will pass some state in this case only.

As usual, pull requests are most gratefully appreciated, see

If you are interested in filter QOL, there's a mostly-complete PR to add fully composable customisable filters. The author isn't available and I just don't have the bandwidth to push it through.

#3121