17

I have opened a dir vim some/dir. I can navigate within the tree, yet once I opened a file I wonder, how do I close the file view in order to go back to the directory listing to navigate to another file. :wq is no option, as it closes the whole vim session. I guess there is a for mode to that, yet I do not know what it is called nor how I start it.

How to close the file to file navigation view?

16

How about :e .? This opens the current directory in Vim, i.e. it opens the file explorer. Because I have autochdir setting set, this shows the directory that the currently edited file is in.

  • 1
    Alternatively, :E has the same effect. – Jochem Schulenklopper Nov 1 '15 at 12:37
  • :E actually has a slightly different affect, :e . will open a new buffer where :E will open a hidden buffer. So :E will keep you buffer list cleaner. – Michael Daffin Aug 16 '16 at 10:56
11

I'm not sure but I think that you want the :rew command

  • 3
    You could give some additional details, telling that it comes from :rewind and it “Start editing the first file in the argument list.” – manatwork Oct 18 '12 at 11:00
  • :fir (standing for :first) is the same. – Enrico Maria De Angelis Aug 26 '16 at 9:53
9

Use ^O to fallback previous opened file, which is your dir tree in this case.

3

If you want to close a file use :bd (buffer delete). This will take you back to the previous buffer, in your case the directory listing. You can have multiple files open at once in vim, each is known stored and referred to as a buffer.

If you do not want to close the current file you can also use :E (explore) to open a view of the current directory where you can open other files. If you know the file name you can simply :e path/to/file.txt to open it directly. You can then switch between buffers with :bn and :bp.

Note: since you opened the dir view as a buffer (rather then with :E) you can switch to it any way you normally switch to a buffer (:bp, :bp, :b 1, :rew, :first etc). Use :ls to list your open buffers.

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.