Giter Site home page Giter Site logo

No buffer shown for netrw about vim-buftabline HOT 7 OPEN

gibfahn avatar gibfahn commented on August 20, 2024
No buffer shown for netrw

from vim-buftabline.

Comments (7)

ap avatar ap commented on August 20, 2024 1

You can hit o on a file to open it in a new buffer, or t to open it into a new tab. Other operations are not yet supported but I intend to add them.

Switching buffers does work – it’s what readdir does when you try to open an already-open file. But I found it rather disorienting for directories, because your navigation actions suddenly affect a different directory browser than the one you started with. It would only make sense if you could never change directory within a browser but only open directories, as new buffers. That would make some amount of sense, even… but navigating around your filesystem would quickly accumulate lots of open directory buffers. Dunno if that would really be usable.

from vim-buftabline.

ap avatar ap commented on August 20, 2024

It uses the buffer number, not the buffer name. So I have no idea how this situation can happen.

What does :echo buftabline#user_buffers() say? And :echo winbufnr(0) when you’re in the netrw buffer?

from vim-buftabline.

gibfahn avatar gibfahn commented on August 20, 2024

:echo buftabline#user_buffers() shows [1, 2, 3, 4]
:echo winbufnr(0) shows 5

from vim-buftabline.

ap avatar ap commented on August 20, 2024

Ohhh, I think I remember now… this is one of these bizarro aspects of netrw. When you open a directory, netrw creates an unlisted unnamed alternative buffer for it and renders the directory into that buffer, and then (if I still have the details right) intercepts switches into the regular (and named) buffer and flips you over to the rendered version in the alternative buffer. This is not something that can be handled without specific support for netrw… and I think I didn’t find a way to detect it reliably at the time (my memory is really hazy at this point…).

I vaguely remember this being among the things that drove me to write readdir (“gee, this has to be doable in a less crazy way”).

Edit: jinx…

from vim-buftabline.

gibfahn avatar gibfahn commented on August 20, 2024

Okay, that would make sense, so netrw is in buffer 4 but is randomly also working in buffer 5 somehow?

If you're saying the easiest way to fix this is to use readdir, then fair enough, I'll try it out!

from vim-buftabline.

ap avatar ap commented on August 20, 2024

Well buffer 4 has the directory name but there is nothing in it. And buffer 5 has no name and is not listed but has the directory contents in it. And when you switch to buffer 4, netrw forces you into buffer 5.

I must admit that after having written readdir and run into the same design issues, I can now appreciate why netrw chose this design. I addressed those issues by modifying the buffer name instead, but that creates a variety of other design problems that I then had to work around. I’m not wild about either design.

The fundamental problem is that in Vim, no two buffers can have the same name. So if you render a directory into the buffer directly named after the directory, you cannot have two directory browser buffers showing the same directory. E.g. if you are browsing your home directory in one buffer and ~/.vim/ in the other, you cannot go up one directory in the ~/.vim/ buffer because you already have ~/ open in another buffer.

In readdir I reacted to this by setting buftype to nofile to divorce the buffer name from the filesystem, and then adding a unique ID to it. That way multiple readdir buffers can never have the same name even when they’re showing the same directory. But then this has to be undone to open a file, and also, changing the name of a buffer interacts a little weirdly with later opening a file into that same buffer, so I had to find a workaround for that, etc etc.

In netrw they solved all this by doing this alternative unlisted buffer dance instead. In some ways this is less crazy – using multiple buffers isolates the state of each of them, so it’s simpler and more robust compared to readdir, which has to carefully track each bit of buffer state that it relies on. But the netrw bodge is also more visible to the user.

Both approaches suck in different ways. But under Vim’s constraint that buffer names must be unique, I can’t think of any better alternative.

from vim-buftabline.

gibfahn avatar gibfahn commented on August 20, 2024

Hmm, could you just switch buffers when the user tries to cd into a directory that is already open in another buffer? If I have Buffer 1 open at ~, and Buffer 2 open at ~/.vim, and I try to open .. in Buffer 2, you could just leave Buffer 2 as is and switch me into Buffer 1. Or would that not work?

Also, in readdir is there a way to open a file without closing the directory buffer? Put another way, is there a way to open multiple files from a single readdir buffer? I was thinking something like <S-Enter>.

from vim-buftabline.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.