32

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?

3

4 Answers 4

36

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.

2
  • 5
    Alternatively, :E has the same effect. Nov 1, 2015 at 12:37
  • 2
    :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. Aug 16, 2016 at 10:56
11

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

11

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

2
  • 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, 2012 at 11:00
  • :fir (standing for :first) is the same.
    – Enlico
    Aug 26, 2016 at 9:53
6

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.

You must log in to answer this question.

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