31

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?

k0pernikus
  • 14,853
  • 21
  • 58
  • 79
  • 2
    I didn't realise you could browse files from that folder view in vim. +1 – Alex Leach Oct 18 '12 at 11:13
  • All solutions in [How to go back to previous opened file in Vim?](https://stackoverflow.com/questions/19971023/how-to-go-back-to-previous-opened-file-in-vim) should also work here. – user202729 Sep 05 '18 at 13:28
  • In order to switch the focus between the opened split views, Ctrl-W + navigation keys(h/j/k/l) can be used. – sanoj subran Jul 16 '22 at 20:23

4 Answers4

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.

k0pernikus
  • 14,853
  • 21
  • 58
  • 79
daniel kullmann
  • 9,427
  • 11
  • 38
  • 45
11

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

daisy
  • 53,527
  • 78
  • 236
  • 383
11

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

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.

Michael Daffin
  • 3,948
  • 1
  • 12
  • 21