Reputation: 5038
When I open a directory browsing in vim, I can open a file by moving the cursor to a file name and pressing Enter.
Now, is there any command to go back to the previous directory browsing?
If not, is there a way to open a file without closing the directory browsing mode?
Upvotes: 199
Views: 81795
Reputation: 6770
You can go back to the last buffer using :b#
.
If you just opened a file, then it will bring you just back to the directory browsing.
Update: Since this answer happened to be accept as the correct answer and is thus on the top, I'd like to summarize a bit the answers, including the one by @romainl that imho is the correct one.
:Rex[plore]
: Return to Explorer (by @romainl) vimdoc.sourceforge:Explorer
: opens the Explorer, same as :E
(if no other command starting with E
is defined (see stackoverflow), or as :Ex
(see vim.wikia) (by @drug_user841417).:b#
: goes back to the "previously edited buffers". See vim.wikia:e#
or Ctrl
-6
(or Ctrl
-^
): goes back to the "previously edited file" (by @aman-jain). See vim.wikiaCtrl
-O
: jump back to the previous (older) location, not necessarily a buffer (by @Peyman). See vim.wikiaUpvotes: 321
Reputation: 71
I'd like to use the Jump-motions shortcut keys to do any 'go back' or 'go forward' actions in Vim. It makes vim like a web browser.
You can search for Vim's help for more details.
Vim
:h jump-motions
So like as mentioned in other answers ctrl+O works cool, and hope vim's help-file let you learn more commands like ctrl+I .
Ctrl + I : Go Forward
Ctrl + O : Go Back
Upvotes: 4
Reputation: 6942
I usually just use :E
. It's easy to remember and gets you back to the directory listing of the file you had open.
Upvotes: 34
Reputation: 196496
The proper command for returning to the netrw listing is :Rex[plore]
. You can run it even after you have jumped to and from dozens of files.
Upvotes: 53
Reputation: 827
:Ex
will take you back (and show you what you edited and didn't save).
Upvotes: 40