Vim,Java:在游标下打开类并转到方法

时间:2021-11-20 22:53:34

Vim can open a file under cursor using gf. For example, if I have the following under my cursor:

Vim可以使用gf在光标下打开一个文件。例如,如果我在光标下面有以下内容:

SensorManagementActivity.java

Hitting gf will open SensorManagementActivity.java.

点击gf将打开SensorManagementActivity.java。

The problem is that in Java, the references lack the java suffix, and often appear as SomeClass, SomeClass() or SomeClass.method().

问题是在Java中,引用缺少java后缀,并且通常显示为SomeClass,SomeClass()或SomeClass.method()。

  • How do I open SomeClass.java and jump to someMethod() when the cursor is on SomeClass.someMethod() in another file?
  • 当光标位于另一个文件中的SomeClass.someMethod()时,如何打开SomeClass.java并跳转到someMethod()?
  • Is there a way to open a new file without saving the current one, and going back to the current one without losing changes?
  • 有没有办法在不保存当前文件的情况下打开新文件,并在不丢失更改的情况下返回当前文件?

1 个解决方案

#1


5  

The 'suffixesadd' option allows gf to handle Java file extensions; it is already set by the java filetype that ships with Vim, like this:

'suffixesadd'选项允许gf处理Java文件扩展名;它已经由Vim附带的java文件类型设置,如下所示:

:setlocal suffixesadd=.java

To jump to methods, Vim can use a tags file that must be (re-)generated first (there are plugins that can automate that). For Java, you can use the exuberant ctags tool.

要跳转到方法,Vim可以使用必须首先(重新)生成的标记文件(有些插件可以自动生成)。对于Java,您可以使用繁琐的ctags工具。

:! ctags -R

For more information and alternatives, read :help ctags. Use the :tag command or the Ctrl-] shortcut to jump.

有关更多信息和替代方案,请阅读:help ctags。使用:tag命令或Ctrl-]快捷键进行跳转。

You can jump to a split window via Ctrl-W ]. To be able to leave a modified file and return back to it later, :set hidden in your ~/.vimrc.

您可以通过Ctrl-W跳转到拆分窗口。为了能够保留修改后的文件并稍后返回,请:在〜/ .vimrc中设置隐藏。

PS: Though here they're kind of related, it's best to avoid asking multiple questions at Stack Overflow

PS:虽然在这里它们有点相关,但最好避免在Stack Overflow上提出多个问题

#1


5  

The 'suffixesadd' option allows gf to handle Java file extensions; it is already set by the java filetype that ships with Vim, like this:

'suffixesadd'选项允许gf处理Java文件扩展名;它已经由Vim附带的java文件类型设置,如下所示:

:setlocal suffixesadd=.java

To jump to methods, Vim can use a tags file that must be (re-)generated first (there are plugins that can automate that). For Java, you can use the exuberant ctags tool.

要跳转到方法,Vim可以使用必须首先(重新)生成的标记文件(有些插件可以自动生成)。对于Java,您可以使用繁琐的ctags工具。

:! ctags -R

For more information and alternatives, read :help ctags. Use the :tag command or the Ctrl-] shortcut to jump.

有关更多信息和替代方案,请阅读:help ctags。使用:tag命令或Ctrl-]快捷键进行跳转。

You can jump to a split window via Ctrl-W ]. To be able to leave a modified file and return back to it later, :set hidden in your ~/.vimrc.

您可以通过Ctrl-W跳转到拆分窗口。为了能够保留修改后的文件并稍后返回,请:在〜/ .vimrc中设置隐藏。

PS: Though here they're kind of related, it's best to avoid asking multiple questions at Stack Overflow

PS:虽然在这里它们有点相关,但最好避免在Stack Overflow上提出多个问题