Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

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

like image 632
Thomson Avatar asked Oct 03 '22 11:10

Thomson


1 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 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.

like image 280
Zaffy Avatar answered Oct 12 '22 01:10

Zaffy