简体   繁体   English

在 vim 中编辑文件时无法 go 到标签

[英]Unable to go to tags while editing a file in vim

I'm editing a source file in Vim, and in the middle of it I want to search for a tag (to understand some variable/class/method etc.), and I click Ctrl+] to look for the tag, and if the tag is supposed to be in a different file, it doesn't allow me to move away from the current file because it is being edited - it displays the usual Vim error - "E37: No write since last change (add ! to override)"我正在编辑 Vim 中的源文件,在其中我想搜索一个标签(以了解一些变量/类/方法等),然后单击Ctrl+]来查找标签,如果标签应该在不同的文件中,它不允许我离开当前文件,因为它正在被编辑- 它显示通常的 Vim 错误 - “E37:自上次更改以来没有写入(添加!覆盖) "

The workaround I have is to save the file first and re-open it and then look for the tag.我的解决方法是先保存文件并重新打开它,然后查找标签。

Is there a way to search the tags without having to save and reopen the file.有没有一种方法可以搜索标签而无需保存并重新打开文件。

You can put the following line in your vimrc to allow Vim to edit another buffer without having to write the current one:你可以在你的vimrc中加入下面一行,让 Vim 编辑另一个缓冲区,而不必写入当前缓冲区:

set hidden

See :help 'hidden' .请参阅:help 'hidden'

If you don't want to set that option, the alternative would be to use <Cw>] , which opens the tag in a new window.如果您不想设置该选项,则替代方法是使用<Cw>] ,它会在新的 window 中打开标签。 See :help ctrl-w_] .请参阅:help ctrl-w_]

Not that, as pointed out in a comment, you don't have to write and quit the current buffer in order to jump to a tag: writing it is enough.并不是说,正如评论中所指出的,您不必为了跳转到标签而写入并退出当前缓冲区:写入它就足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM