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?
Asked
Active
Viewed 9.3k times
2 Answers
299
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.

Zaffy
- 16,801
- 8
- 50
- 77
-
40Just for clarification, both `CTRL-^` (i.e. `CTRL-SHIFT-6`) and `CTRL-6` work for me. – Taylor D. Edmiston Jul 19 '17 at 13:50
-
5For quick access: nmap
bb – me_astr Jul 13 '20 at 12:28 -
Doesn't work on mac – manuch100 Jun 28 '22 at 22:56
-
`CTRL-SHIFT-6` works for me on macos 12.5.1 – Leo Sep 20 '22 at 09:32
165
Try following command
:e#
It will take you to the previously opened file stored in a buffer.
If you have gone deep down the hierarchy of files by typing multiple gf
, vim stores all the files in numbered buffers
Then following command will take you to the n
th file in a buffer. (n = 1,2,3,..)
:e#n

jkshah
- 11,387
- 6
- 35
- 45
-
Is there a way to store files in a register like with recording or yanking? – Daniel Thompson Mar 20 '18 at 03:06
-
ctrl-^ is a little awkward on the fingers imo, this may be slightly slower but not as frustrating. – Isaac Pak Nov 03 '18 at 20:00
-
@DanielThompson what you're looking for is buffers https://medium.com/@Sohjiro/introduction-to-vim-buffers-dd966ff518d – Michael Brown Apr 11 '19 at 14:23
-
1@IsaacPak ctrl + 6 will also work, the way to press it is ctrl (left pinky) + ^ (right index) in qwerty keyboards. – vishless Mar 28 '20 at 01:10
-
1using neovim here, with control mapped to caps lock, and pressing control+shift+6 is some serious finger gymnastics ♂️ – ipatch May 28 '20 at 17:59
-
Is there documentation about `#` and the rest of the "special file aliases"? – Max Coplan Jan 06 '22 at 18:05