How to go back to previous opened file in Vim? [duplicate]

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 already was a current file name, then that one becomes the alternate
file name. It can be used with “#” on the command line |:_#| and you can use
the |CTRL-^| command to toggle between the current and the alternate file.
However, the alternate file name is not changed when |:keepalt| is used.
An alternate file name is remembered for each window.

Leave a Comment