I am browsing the files in vim file explorer by entering vim dirname.

Then I am opening the file, saving and closing it by entering :wq. Now the file explorer window disappears.

How to prevent this behavior?

  • My personal preference: open your file in vim, run :Vex (or :Sex, I promise it's horizontal split). This will either vertically (or horizontally) split your window and run :Ex which will break it out into another pane in your current window. As for disabling behavior, I'm sure that can be accomplished in your .vimrc, but will leave that for someone else to post. :) – bgregs Jan 16 '19 at 13:55
  • 1
    When in :Explore mode, you can go to the parent directory with minus (-). I mapped the minus symbol to :Explore in normal mode and it feels very natural to me. It's a personal preference but maybe you can use it as well: map - :Explore<CR> – Johan Jan 16 '19 at 14:58
  • @Johan Thanks for the suggestion. I didn't know that we could map like this. – Prajwal Jan 16 '19 at 15:41
  • No problem. Just to be clear: It is meant for in your .vimrc file :) – Johan Jan 16 '19 at 16:29

The :quit command (also as part of :wq) quits Vim if this is the last window. As you use :Explore, the opened file replaces the netrw explorer, and exiting Vim is the result.

If you want to keep the file explorer, you can open it in a split window, with :Vex (vertical split) or :Sex (horizontal split). That way, when you close the file, another window is still open and Vim won't quit.

Also, inside a netrw explorer, if you open the file with o / v instead of <Enter>, the explorer will be kept and the file opened in a split; cp. :help netrw-browse-maps. You could also reconfigure the default behavior on <Enter> via :help g:netrw_browse_split.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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