Jumping back to a previously opened file in Vim

与世无争的帅哥 提交于 2020-01-01 07:34:09

问题


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?


回答1:


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



回答2:


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.




回答3:


Another useful feature that comes handy is the uppercase marks. These marks are not local to a buffer and can be used to jump to them from across files. If you mark the line as say "A" using mA command before starting a long and arduous jumping around task, you can finally return back to the original position quickly by typing 'A or `A.




回答4:


You might want to consider using a few vim extensions that make this even simpler.

lusty-juggler and lusty-explorer

http://www.vim.org/scripts/script.php?script_id=2050 http://www.vim.org/scripts/script.php?script_id=1890

These require that vim was built with +ruby.

% vim --version | grep +ruby

They're very useful for staying in vim and jumping between files.



来源:https://stackoverflow.com/questions/1728311/jumping-back-to-a-previously-opened-file-in-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!