neo-tree.nvim icon indicating copy to clipboard operation
neo-tree.nvim copied to clipboard

Can the buffers source show _all_ buffers?

Open miversen33 opened this issue 2 years ago • 9 comments

Discussed in https://github.com/nvim-neo-tree/neo-tree.nvim/discussions/884

Originally posted by miversen33 April 19, 2023 I am currently trying out the buffers source (in an effort to get rid of using a statusbar to track everything). However, buffers only seems to show active buffers in my cwd.

I see there is a buffers.bind_to_cwd option, but setting that to false does not change that I cannot see buffers not in my cwd :( Am I missing something or do I need to open an issue and investigate this?

Edit: More interesting, opening new buffers after opening the buffers source seems to reflect them, but not new files... Switching this to an issue.

miversen33 avatar Apr 20 '23 02:04 miversen33

I will hammer out steps to reproduce what I am seeing, though it could also just be that I am expecting more than the source is currently designed to do.

Basically, when I open Neo-tree, the buffer source shows the current "empty" buffer image

This seems right. When I open a file in my cwd, I see that buffer open. Also good image

Open a file outside the cwd? No dice image

Current Config

{
    popup_border_style = 'rounded',
    source_selector = {
        winbar = true,
        sources = {
            { source = "filesystem" },
            { source = "buffers" },
            { source = "document_symbols" },
            { source = "remote" },
        }
    },
    default_component_configs = {
        name = {
            highlight_opened_files = "all",
        }
    },
    sources = {
        "filesystem",
        "buffers",
        "document_symbols",
        "netman.ui.neo-tree",
    },
    buffers = {
        bind_to_cwd = false,
    },
    filesystem = {
        filtered_items = {
            visible = true,
            hide_gitignored = false,
            hide_hidden = false,
            hide_dotfiles = false,
        },
        follow_current_file = true,
    },
}

I will work to pair this down to a minimal config and update this comment with that at the end of it

miversen33 avatar Apr 20 '23 02:04 miversen33

@miversen33 this is exactly how it is supposed to work, it's not a bug. If you want to see open buffers that are not in your cwd, just change your cwd!

The reason that it was designed this way is that I when I created it, my workflow was to have one instance of nvim and use tabs to separate out different projects with different cwd. It make sense then that each tab would show just the buffers in that project. If the buffers source showed all buffers regardless of cwd, then it would break this concept of using tabs to designate separate projects.

Technically, I no longer use tabs and just use different instances in tmux windows now, but I rarely would open a file that is not in my cwd, so it still fits just fine. On the extremely rare occasion where I do want to open a file that is not in my cwd, I would want to navigate my cwd up to whatever the common cwd is anyhow.

The only place this might not fit is with tmp files like with commit messages, but I don't normally want to go back to them once I am done with them anyhow so I don't feel the need to show them in a buffers list.

cseickel avatar Apr 20 '23 12:04 cseickel

Sounds like it's working as intended. I'll find a different solution for what I need then :)

miversen33 avatar Apr 20 '23 12:04 miversen33

I suppose we could add an option to auto_change_cwd on this source which would automatically change the root dir to whatever is the common root of all open files. Then if all of the open files do fall within the cwd, just use that, but if they don't, then temporarily use whatever root would show all open files. This would be evaluated on every refresh.

cseickel avatar Apr 20 '23 12:04 cseickel

I don't know that I like the idea of the buffers source automatically executing cds (even if the option is off by default). When I opened the source, I saw "buffers" and assumed it would show "buffers" lol. But that is simply a misunderstanding on my part. If it is working as intended, then that means that what I was expecting is incorrect. I haven't checked out the code for the source, so I don't know the work effort to show "all" buffers and tree just the CWD buffers (the UX I expected). I am willing to simply accept this source doesn't fit the needs I was hoping lol.

miversen33 avatar Apr 20 '23 12:04 miversen33

I don't know that I like the idea of the buffers source automatically executing cds (even if the option is off by default).

That's not actually what I meant. I meant to say that the with this option, the buffers source will no longer lock it's root to the cwd, the cwd will just be a starting point but it will use whatever root is needed to show all open buffers.

This option is mutually exclusive from bind_to_cwd and it would be an error to enable both at the same time.

cseickel avatar Apr 20 '23 13:04 cseickel

Ahh gotcha. I don't hate that idea, though I also don't know the work effort of that. Honestly I am willing to accept the state of the source as is, though if you really think we should consider that, I am not against it either.

miversen33 avatar Apr 20 '23 14:04 miversen33

It shouldn't be difficult, but then again:

image

I think it's worth leaving the issue open though, I might do it someday.

cseickel avatar Apr 20 '23 17:04 cseickel

I'm looking for some nvim plugins that implement the vertical buffer list and this ticket leads me here.

I'd like to share another use case like mine. I'm working on the Android system development, a really large amount of projects and complicated cross-project references. These amounts of related sources could easily make some buffer line plugins hard to use since the horizontal layout is too crowded to show these files. If neo-tree could provide this feature, a vertical buffer list, without the cwd limitation, it would be really helpful for some people like me. Thanks~

liangkarl avatar Jan 27 '24 06:01 liangkarl