question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

  • 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:closed
  • Created 3 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Shougocommented, Jun 29, 2020

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.

1reaction
Shougocommented, Jun 29, 2020

I have added -close option for it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature request: Close Defx buffer after opening a file #67
I want to open in a horizontal split and close the defx buffer but the following doesn't quite work. nnoremap <silent><buffer><expr> s ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found