Shougo / defx.nvim

:file_folder: The dark powered file explorer implementation for neovim/Vim8
MIT License
1.17k stars 86 forks source link

[Question] Close Defx before closing/saving session with Startify #225

Closed idr4n closed 4 years ago

idr4n commented 4 years ago

Warning: I will close the issue without the minimal init.vim and the reproduction instructions.

Problems summary

If Defx is open and I close the session with :SClose (which saves and closes the session) using Startify, then when I reopen/load the session I get the message '"[defx] -0" [Not Edited] --No Lines in buffer--' and the window where Defx was at is empty of course. This is assuming that I had open Defx in a vertical split.

Also, I have the following mapping to close Nerdtree when it is open and I close another buffer (so Nerdtree is not hanging there as last Window open)

nnoremap <expr> <silent> <leader>q g:NERDTree.IsOpen() ? ':NERDTreeClose<CR>:bd<CR>' : ':bd<CR>'

Can I do something similar for Defx as well?

Expected

With NerdTree I manage to avoid this as Startify provides a option to perform a command before saving a session and NerdTree has a command to close it:

let g:startify_session_before_save = [
      \ 'silent! NERDTreeClose',
      \ ]

I would like to be able to do something similar so I don't have to close Defx before closing the session or before deleting a buffer.

Environment Information

Latest (how do I check?)

Provide a minimal init.vim/vimrc with less than 50 lines (Required!)

call defx#custom#option('_', {
      \ 'winwidth': 27,
      \ 'split': 'vertical',
      \ 'direction': 'topleft',
      \ 'show_ignored_files': 0,
      \ 'buffer_name': '',
      \ 'toggle': 0,
      \ 'resume': 1
      \ })

call defx#custom#column('icon', {
      \ 'directory_icon': '▸',
      \ 'opened_icon': '▾',
      \ 'root_icon': ' ',
      \ })

nnoremap <silent> ,e :Defx -toggle<CR>
nnoremap <silent> ,f :Defx -search=`expand('%:p')`<CR>

"" Startify
let g:startify_session_dir = '~/.config/nvim/sessions'
let g:startify_session_delete_buffers = 1
let g:startify_change_to_vcs_root = 1
let g:startify_session_persistence = 1
let g:startify_enable_special = 1
let g:startify_session_before_save = [
      \ 'silent! NERDTreeClose',
      \ ]
Shougo commented 4 years ago

Why Startify saves nofile buffers? I don't understand.

Shougo commented 4 years ago

I don't want to add :DefxClose like command.

Shougo commented 4 years ago

Can I do something similar for Defx as well?

You can use :Defx -toggle

idr4n commented 4 years ago

I don't know why Startify saves nofile buffers, but it happens woth NerdTree, coc-explorer, and Defx.

:Defx -toggle would not solve the issue as then if Defx is not open, Startify would open it before saving, and I don't keep Defx or any file manager open all the time, but when I do i don't want to worry about closing it first.

Any suggestion about any other session manager that supports Defx, or that doesn't save nofile buffers?

idr4n commented 4 years ago

I could raise this issue to Startify instead.

Shougo commented 4 years ago

I have added -close option for it.

Shougo commented 4 years ago

Any suggestion about any other session manager that supports Defx, or that doesn't save nofile buffers?

I don't like session managers...

idr4n commented 4 years ago

Thanks, -close works as expected.

Btw, is there a way to check whether Defx is open? Like with the name of the buffer, perhaps. But haven't been able to figure it out what buffer name is given to Defx.

Shougo commented 4 years ago

Btw, is there a way to check whether Defx is open? Like with the name of the buffer, perhaps. But haven't been able to figure it out what buffer name is given to Defx.

You should check defx filetype buffers instead of filename or check b:defx exists. You can write Vim script for it.