I've set up an autocmd to automatically create directories of the filepath I'm writing to: au BufWritePre,FileWritePre * call <SID>EnsureDir(expand('<afile>:p:h')). This prevents creating directories when I discard the buffer.

I'd like to continue to be able to use stdin, provide url filepaths, and read files into buffers from within vim as normal. But how can I use netrw's features yet prevent it's FileExplorer autocmd (on VimEnter) to act on new/nonexistent, local files? What's a good approach to this?

I hope it's clear what i'm asking. I'm suprised that I could not find a similar question. I read pi_netrw.txt, but could not find a method there. I use neovim version 0.2.2 on linux 4.14.3-1-ARCH.

  • It's not clear to me what you're asking. You're talking about writing to new dirs/files after you've started Vim so how does a VimEnter autocommand pose a problem?
    – B Layer
    Commented Dec 10, 2017 at 10:57
  • 1
    I'm so sorry. When testing with a -u testrc.vim, I did not properly check all scriptnames. There's a custom file in /usr/share/.. that has a function which is resolving the autocmd match on BufNewFile I forgot about. I added an isdirectory check, and now everything is fine.
    – Bart
    Commented Dec 10, 2017 at 14:24
  • That's okay. Glad you got it straightened out.
    – B Layer
    Commented Dec 10, 2017 at 14:39

1 Answer 1


When testing, I could not disable plugins. I forgot about a file in /usr/local/share/nvim/site/... It turns out that I silently ran a bwipeout and edit when incorrectly handling <amatch> on a BufNewFile autocmd. I simplified my knotty setup and included a simple isdirectory() check.

netrwPlugin.vim behaves as expected (at least for my usage). sorry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.