`DirbufWipe`: A Way to Quit/Close Dirbuf Without Losing its Split
jeetsukumaran opened this issue ยท 5 comments
This is not immediately related to #28, but this feature would definitely support it. But it also is its own goal and will be useful
Use case:
- I have opened up Dirbuf in an existing window or split (e.g., using the
:Dirbuf
command). - I want to close it without opening a file AND without closing the window or split in which I opened.
- Expected
Dirbuf
behavior: when issuing theDirbufWipe
command:- If the window in which
Dirbuf
was rendered had another buffer in view beforeDirbuf
occupied it, restore that buffer in the window before self-deleting theDirbuf
buffer. Note: this requires that Dirbuf record the previous buffer that occupied the window it was called in when invoked (stored in, for e.g.,b:dirbuf_widnow_prev_buffer
), or otherwise record a null flag for this attribute (e.g., 0 or -) if Dirbuf was opened in a new split. - If the window in which
Dirbuf
was rendered did NOT have another buffer in view beforeDirbuf
occupied it (such thatb:dirbuf_widnow_prev_buffer==0
for e.g.), then:- If there are no other open windows or splits or tabs, then Dirbuf should refuse to quit
- Otherwise, the Dirbuf buffer is wiped (
:bwipe!
) and the let the splits fall where they may
- If the window in which
I think this behavior is not unusual, and is generally how some might expect windows/buffers like this to work given many other plugins working like this.
I like this! Personally, I prefer a name like :DirbufQuit
or :DirbufClose
because dirbufs are automatically wiped when they are closed. I'll have to see what other plugins call this, but this seems like a very reasonable and easy feature
@jeetsukumaran What are your thoughts on a default key mapping for :DirbufQuit
?
Also, you can check out the quit
branch. There's a new :DirbufQuit
command which should work how you were proposing except for the case where there are no other open windows or splits or tabs, then it closes the directory buffer and just replaces it with a [No Name]
buffer, which I think is more reasonable (and easier to implement ๐).
I thought I had responded to this earlier, but it seems like that got lost :(
First off, THANK YOU for such a nice and prompt solution!
This works like a charm.
It makes using Dirbuf seamless as you can hop in an out without thinking about it and with no disruption of your workflow: it's there when you want it, and gone without any fuss when you don't.
I've got the following in my ~/.vimrc
to use Dirbuf
to open vertical/horizontal splits:
" Dirbuf {{{2
" git@github.com:elihunter173/dirbuf.nvim.git
function! s:_dirbuf_open(cmd)
execute ":lua require('dirbuf').enter('" . a:cmd . "')"
wincmd p
:DirbufQuit
endfunction!
function! s:_dirbuf_setup()
nmap <silent> <buffer> <C-v> :call <SID>_dirbuf_open("vsplit")<CR>
nmap <silent> <buffer> <C-s> :call <SID>_dirbuf_open("split")<CR>
nmap <silent> <buffer> yy :lua require("dirbuf").get_cursor_path()<CR>
nmap <silent> <buffer> Y :lua require("dirbuf").get_cursor_path()<CR>
nmap <silent> <buffer> o <CR>
nmap <silent> <buffer> q :DirbufQuit<CR>
nmap <silent> <buffer> <Esc> :DirbufQuit<CR>
endfunction
autocmd! FileType dirbuf :call <SID>_dirbuf_setup()
" }}}2
Awesome! I'm glad you like it. It's been merged to main.
One thing that would be nice -- the ability to call DirbufQuit
from any window/buffer. This will allow me to bind a global hotkey to quit the buffer from any window without first navigating to whatever window Dirbuf is in to close it.