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.

Opening defx when running `:e /some/directory/`

See original GitHub issue

Hi, apologies for not using your issue template! This is more of a question that I’m hoping for a quick answer to so that I can close this and file a more detailed issue if necessary.

I recently switched over to defx from vimfiler and I’m enjoying it, but I noticed that one feature of vimfiler appears to be missing in defx: the behavior where if you run :e /path/to/some/directory, vimfiler would open in that directory.

A variant of this is that if you ran vim /path/to/some/directory at the command-line, Vim would open and display vimfiler in that directory.

I’m not actually 100% sure that vimfiler provided this functionality, or if it was baked into Vim somehow that Vim would open a file explorer if you provide a directory as the argument to :e. Do you know where this behavior was coming from, and how I might be able to implement it with defx?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
daveyarwoodcommented, May 6, 2020

I was able to re-implement this behavior as a straightforward autocmd:

function! s:defx_my_settings() abort
  " ... configure defx as per :help defx-examples ...
endfunction

function! s:open_defx_if_directory()
  " This throws an error if the buffer name contains unusual characters like
  " [[buffergator]]. Desired behavior in those scenarios is to consider the
  " buffer not to be a directory.
  try
    let l:full_path = expand(expand('%:p'))
  catch
    return
  endtry

  " If the path is a directory, delete the (useless) buffer and open defx for
  " that directory instead.
  if isdirectory(l:full_path)
    execute "Defx `expand('%:p')` | bd " . expand('%:r')
  endif
endfunction

augroup defx_config
  autocmd!
  autocmd FileType defx call s:defx_my_settings()

  " It seems like BufReadPost should work for this, but for some reason, I can't
  " get it to fire. BufEnter seems to be more reliable.
  autocmd BufEnter * call s:open_defx_if_directory()
augroup END
3reactions
Deerhound579commented, May 15, 2020

When I do this, I will have a useless buffer with the directory name in addition to the defx window. For those who encounter this problem, this is my fix. It might not be the best way but works.

if isdirectory(l:full_path)
    execute "Defx `expand('%:p')` | bd " . expand('%:r') 
endif
Read more comments on GitHub >

github_iconTop Results From Across the Web

doc/defx.txt · zgpio/defx.nvim - Gitee.com
Q: I want to open defx when running `:e /some/directory/` like netrw. A: https://github.com/Shougo/defx.nvim/issues/175. Q: I want to open file by double ...
Read more >
Shougo/defx.nvim - Gitter
run :Defx , the defx windows will be opened, and cursor move to defx windows, run :Defx command again, another defx windows is...
Read more >
Viewing online file analysis results for 'Firefox Installer.exe'
Reads the cryptographic machine GUID; Spreading: Opens the ... Contains ability to open the clipboard ... Installs hooks/patches the running process.
Read more >
ターミナルから直接defx.nvimのエクスプローラを開く方法
defx.nvimをインストール済みで,ターミナルからコマンド1つでdefxの ... defx.nvim · Opening defx when running :e /some/directory/ #175.
Read more >
Defx: file explorer plugin for Neovim - eed3si9n
That's pretty much what you get when you open Sublime Text or VS Code. ... I made <Space>-e to split Defx to the...
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