[Question] Close Defx before closing/saving session with Startify
See original GitHub issueWarning: 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
- defx version(SHA1):
Latest (how do I check?)
-
OS: MacOS Catalina
-
neovim/Vim version: Neovim v0.4.3
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',
\ ]
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (6 by maintainers)
Top GitHub Comments
You should check
defx
filetype buffers instead of filename or checkb:defx
exists. You can write Vim script for it.I have added
-close
option for it.