简体   繁体   English

在 Eclipse 中跳转到块的开头/结尾

[英]Jump to beginning/end of block in Eclipse

First off, I'm not looking for CTRL + SHIFT + P , but something a little more flexible.首先,我不是在寻找CTRL + SHIFT + P ,而是在寻找更灵活的东西。 Is there any way to jump from anywhere inside a block to the beginning or end of that block?有没有办法从块内的任何地方跳转到该块的开头或结尾?

CTRL + SHIFT + UP works and takes you to the beginning of the function. CTRL + SHIFT + UP 起作用并带您到函数的开头。 If you repeat it again takes you to the next function in the upward direction.如果您再次重复,您将进入下一个向上的功能。 CTRL + SHIFT + DOWN takes you to function names in DOWNWARD direction. CTRL + SHIFT + DOWN 会将您带到向下方向的函数名称。

I tried in Version: Mars.1 Release (4.5.1)我试过版本:Mars.1 Release (4.5.1)

I'm afraid the command you are looking for does not exist in vanilla Eclipse.恐怕您要查找的命令在香草 Eclipse 中不存在。

You can try Shift + Alt + , which will select the enclosing element.您可以尝试Shift + Alt + ,这将选择封闭元素。 It should eventually select to whole block.它最终应该选择整个块。 then moves the cursor to the beginning, moves it to the end. 然后将光标移到开头, 将光标移到结尾。

But it really isn't any faster than:但它实际上并不比:

  1. End to jump to the end of the line End跳到行尾
  2. Ctrl + Shift + P to go to end of the block Ctrl + Shift + P转到块的末尾
  3. Ctrl + Shift + P again to go to start of the block再次Ctrl + Shift + P转到块的开头

If your code is somewhat reasonably formatted (ie not everything on one line), this should always work.如果您的代码格式有些合理(即不是所有内容都在一行中),这应该始终有效。

Also check the list of possible shortcuts in Preferences->General->Keys, there isn't one that does what you want.还要检查首选项-> 常规-> 键中可能的快捷方式列表,没有一个可以满足您的需求。

If you have the Outline window visible, you will have the current function highlighted.如果您看到大纲窗口,您将突出显示当前功能。 Click on it and you will go to the function declaration.单击它,您将转到函数声明。 Works in PHP.在 PHP 中工作。

In eclipse on mac, you can go to the top of the file editor using command + .在 mac 上的 eclipse 中,您可以使用command + 转到文件编辑器的顶部。 And you can go to the bottom of the file editor using command + .您可以使用command + 转到文件编辑器的底部。

I am addressing the situation when one wants to find which method does a certain line of code belong to (this is practical for large method blocks, when you have reached a certain line via Search for a keyword within the workspace).我正在解决的情况是,当人们想要查找某行代码属于哪个方法时(这对于大型方法块很实用,当您通过在工作区中搜索关键字到达某行时)。 Of course, this answers a particular sub-case, as methods are blocks of code, too, but not all blocks of code are methods.当然,这回答了一个特定的子案例,因为方法也是代码块,但并非所有代码块都是方法。

One can gradually press Shift+Alt+Up Arrow, as pointed in an above answer, and will eventually have highlighted the entire body of the enclosing method.可以逐渐按 Shift+Alt+Up Arrow,如上述答案中所指出的,最终将突出显示封闭方法的整个主体。

However, when highlighting a piece of code, in the Outline view, it's enclosing method is already highlighted, and clicking on it will bring the focus on the beginning of the method, in the Editor.但是,在突出显示一段代码时,在 Outline 视图中,它的封闭方法已经突出显示,单击它会将焦点放在编辑器中方法的开头。

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

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