Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim: What is the opposite of gf?

Tags:

file

vim

When working with vim, I jump between files with:

  • Tags: ctrl-] and ctrl-t,
  • Jump marks: ctrl-i and ctrl-o as well as
  • Edit locations: g-; and g-,.

What I need is a bit different...

From the file I am in where I jumped to with g-f:
What is the easiest way to reopen the previous file?

All of the mentioned above do not help much if you have lots of changes made since switching files. Jumping back to previous tag will not work either, ofc.

Can any of the gurus here provide me with some insight?

like image 274
sjas Avatar asked Feb 16 '23 23:02

sjas


2 Answers

You can return to the previous buffer using Ctrl-^ or Ctrl-o.

More info

Or if you don't want to save your current changes, do a :tabnew and "2Ctrl-o".

like image 153
perreal Avatar answered Feb 27 '23 07:02

perreal


ctrl-^ (or ctrl-shift-6 on U.S. keyboard layout.) is actually the shortcut for :e#.

See :h alternate-file or :h ctrl-^ for further info.

This makes it possible to swap between the two most recently edited files with the same command, too.

like image 27
sjas Avatar answered Feb 27 '23 08:02

sjas