Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jumping back to a previously opened file in Vim

Tags:

While using Vim I'll sometimes want to look at a function definition or a struct definition, so I'll use C-] to jump to it. However, there are a few problems I run into. First off, I don't know how to jump back easily. It appears the previous file I was in closes and I'm now in the new one. Is there a way to jump back, or keep a stack of open files that I can pop back to or something?

Another thing I've noticed that when I have a change in the current file I need to save it because, like a mentioned a moment ago, my current file is being closed before the next one opens.

And sometimes I want to view my current code and my header at once. Is there a way open the tag definition in a split?

like image 278
Alex Avatar asked Nov 13 '09 10:11

Alex


People also ask

How do I go to a previous file in vim?

Just for clarification, both CTRL-^ (i.e. CTRL-SHIFT-6 ) and CTRL-6 work for me.

How do I revert to a previous version of vi editor?

Since switching back to the previous file is something that tends to happen a lot, you don't have to move to the ex command line to do it. The vi command ^^ (the "control" key with the caret key) will do this for you. Using this command is the same as typing :e #.

How do I go back to the previous line with code?

Go back to previous line hotkey : r/vscode.


2 Answers

Add

set hidden

to you vimrc. It'll allow you switch files without saving them. I think this is one of 'must have' options.

Use C-o to jump back to previous locations which were autosaved in a jumplist.

:h jumplist
like image 118
Maxim Kim Avatar answered Oct 12 '22 04:10

Maxim Kim


To jump back from C-], use C-T. The :tags command shows the current stack.

Set the autowrite option to automatically save what you're doing before jumping to a new file.

Use C-W C-] to open the tag in a new window.

Finally, :help tags is the section in help that explains all this and more.

like image 33
Greg Hewgill Avatar answered Oct 12 '22 04:10

Greg Hewgill