24

I have been trying to figure out how to exit the file explorer in Vim.

:q works, but it closes Vim as well, not just the file browser.

Am I missing something or is this a bug?

1
  • :e works for me just fine.
    – altsyset
    Apr 23, 2020 at 19:48

4 Answers 4

22

The command :bd (delete current buffer) appears to close an active file explorer without closing Vim, even if the explorer is full-screen.

17

This is expected behavior.

If you have an open modified file, :Explore will open a split-screen explorer, and typing :q will return to the opened file. If not, it will open a full-screen explorer, and :q will close vim.

If you want to force the split-screen explorer even when the opened file has not been modified, or if no file has been opened, use :Sexplore instead.

You can also use a tabbed full screen explorer with :Texplore, that probably behaves exactly the way you want. It will open the explorer on a new tab, and typing :q will always close that tab, but not vim.

Please take a look at the Vim documentation about these commands.

1
  • The problem with using :Sexplore is that the file is then opened in the split screen. This is the same with :Texplore.
    – icc97
    Apr 17, 2017 at 21:04
12

In Vim 8 (I haven't tried earlier versions) :Rexplore will work.

In :help :Explore it mentions:

:Rexplore            ... Return to/from Explorer

:Rexplore only actually works when you are in the Explorer.

:Lexplore is also a very nice option, as it will open the vertical explorer, but opening any file from there will open the file in your original window. Then you can close the explore window by typing :Lexplore again. This effectively then works similar to other file explorers like NERDTree or as in editors like Sublime Text. This is different behaviour from :Sexplore / :Vexplore / :Texplore which open the file in the same window as the Explorer.

1
  • I tried :Lexplore and it did not work like you said: doing :Lex after having opened the new file does not close the explore windows but a open a new one, and after doing :q several times to close everything I don't go back to the original file even if I made modifications on it (I lose them without the need of doing :q!).
    – Jean Paul
    Jun 8, 2020 at 20:49
1

:bd work, but if you're open NerdTree, this will close NerdTree and with :Rex, everything works perfectly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .