Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Vim how to jump between two files

Tags:

vim

I need to jump back and forth between two files in Vim.

I can do this manually as :e file1.txt followed by :e file2.txt. Is there a shortcut to directly jump to the previously opened file?

Note: I don't want to open the two files in split windows or multiple tabs.

I'm looking for something like [ctrl + o], only the jump should be to previous file, not previous location in the same file

thanks for any hints

like image 576
Neha Karanjkar Avatar asked Jun 11 '13 10:06

Neha Karanjkar


2 Answers

Use <C-^> or <C-6>.

From :h 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.

If the 'autowrite' or 'autowriteall' option is on and
the buffer was changed, write it.
Mostly the ^ character is positioned on the 6 key,
pressing CTRL and 6 then gets you what we call CTRL-^.
But on some non-US keyboards CTRL-^ is produced in
another way.
like image 79
romainl Avatar answered Nov 17 '22 21:11

romainl


I am not sure I understand correctly, but with only two files opened maybe buffer next :bn will be enough?

like image 38
Grzegorz Gierlik Avatar answered Nov 17 '22 22:11

Grzegorz Gierlik