How to return to the previous open file in Vim?

I can use gf to go to the file with the name under / after the cursor, is there any command to go back to the original file without restarting vim to open it?

+75
vim
Nov 14 '13 at 6:26
source share
2 answers

Try using this shortcut:

 CTRL-^ 

Vim Documentation :help CTRL-^ :

 CTRL-^ Edit the alternate file. Mostly the alternate file is the previously edited file. This is a quick way to toggle between two files. It is equivalent to ":e #", except that it also works when there is no file name. 

And :help alternate-file

If there was already a current file name, then this becomes an alternative file name. It can be used with "#" on the command line |: _ # | and you can use | CTRL- ^ | to switch between the current and alternate file. However, the alternate file name does not change when |: keepalt | is used. An alternate file name is remembered for each window.

+122
Nov 14 '13 at 6:31
source share

Try the following command

 :e# 

It will transfer you to a previously opened file stored in the buffer.




If you deepen the file hierarchy by typing a few gf , vim stores all the files in numbered buffers

Then the following command will lead you to the n file in the buffer. (n = 1,2,3, ...)

 :e#n 
+63
Nov 14 '13 at 6:30
source share



All Articles