Intellij - navigate to type parameter declaration from symbol - scala

In IntelliJ I can navigate to the type declaration of a symbol using Ctrl+Shift+left click, or Ctrl+Shift+B (see IntelliJ Help).
But suppose I have a symbol of type Option[MyType]. How can I navigate, via a series of keyboard shortcuts and/or mouse clicks, to the class where MyType is declared?

I assume you have this case
val xOpt = someMethodReturningAnOption
and so have nothing to ctrl+click on to navigate to the class. And the short cut you use, takes you to the Option. Which is not that useful.
I don't know if it's possible to do in 1 shortcut in intellij 14. What I tend to do is
step 1: Alt+enter on the variable - select "add type annotation". This converts it to something like this.
val xOpt: Option[String] = someMethodReturningAnOption
Step 2: Ctrl+Click on the String Or whatever it is.
Step 3: Once I'm done, Ctrl+tab to go back to my original class (Or ctrl+shift+backspace to last edited location). And undo (Ctrl+Z :)
Its a bit laborious, so a 1 step shortcut would be great to find out.
(FYI: These are my shortcuts used on my linux box )

Related

View All Eclipse shortcuts

I was trying to learn all the eclipse shortcuts... I couldn't find anything useful.
There are some shortcuts available for easy ones, like Find, Find in Files, Comment, Uncomment etc.
Is there any way to view all the eclipse shortcuts?
Clicking Ctrl+Shift+L from eclipse, will list all the shortcuts. This is pretty useful, as you don't need to switch to another window... You can do your work without any interruption.. :-)
Open Windows->Preferences->General->Keys. Now you can use the filter to find your shortcut and change its binding.
CTRL + SHIFT + L
Shows you a list of your currently defined shortcut keys.
However this will only show you custom short cuts that user have added therefore, Please find useful eclipse short-cuts below
CTRL + /
In line Comment
CTRL + SHIFT + /
Block Comment
CTRL + D
Delete row. Try it! You no longer need to grab the mouse and select the line, or select Home, Shift + End, Delete. Quick and clean.
ALT + Up/Down Arrow
Move the row (or the entire selection) up or down. Very useful when rearranging code. You can even select more rows and move them all at once. Notice, that it will be always correctly indented.
ALT + Left/Right Arrow
Move to the last location you edited. Imagine you just created a class "Foo", and now you are working on a class "Boo". Now, if you need to look at the "Foo" class, just press Alt+Left Arrow. Alt+Right Arrow brings you back to "Boo".
CTRL+SHIFT+O
Organize imports. What happens when you first use a class you have not yet imported? You will see an error. But when you press this magical combination, all your missing classes will be imported, and the unused imports will vanish.
CTRL+1
Probably the most useful one. It activates the quick fix. Imagine you create a class, which implements some interface. You will get an error, because the inherited methods are not yet implemented. While you are on line where the error occurs, press this combination to activate the quick fix. Now, select the "Add unimplemented methods" option. You can use the quick fix at every error you ever receive.
Quick fix comes in handy in other situations too. My favorite is the "Split variable declaration". Sometimes I need to broaden the scope of a variable. I activate the quick fix, split declaration, and use alt + arrow to put it where it belongs. You can find even more uses: Convert local variable to field, rename in file, inline local variable, etc...
You could use the "Split variable declaration" on the bar variable, and then move it with Alt+Arrows above the try block..
Or you could use the "Add unimplemented methods" fix here.
The best thing you can do if you see an error is to use the quick fix.
CTRL+SHIFT+T
Open Type. Imagine, that you need to have a look at the "Foo" class. But, where is the "Foo" class? Is it in the "Boo" project and in the "foo.bar" package? Or somewhere else? With this shortcut, you don't need to know. Just press it, type "Foo" and you are in.
CTRL+E
Shows you a list of all open editors.
CTRL+F6
Use to move between open editors. This is a slower alternative to Ctrl + E. It comes in handy in a situation when you want to periodically switch between two editors, something that is nearly impossible with Ctrl+E as it sorts entries quite randomly. Or you might just use Alt+Arrows...
CTRL+F7
Move between views. When in the editor, press Ctrl+F7 to switch to the Package Explorer, or hold Ctrl and press F7 multiple times to switch to other views.
CTRL+F8
Move between perspectives. The same as the previous.
CTRL + F11
Runs the application. What gets launched depends on your settings. It will either launch the last launched class (my preferred way) or it will launch the currently selected resource (the default way). If you want to change its behavior read the previous post.
CTL + N
Open new type wizard. This is not very quick because you have to select the wizard type (whether you want to create new class, jsp, xml or something else) in the next step. A much faster way would be if you could just hit the shortcut and invoke the particular wizard. It is possible, just keep reading...
CTRL + M
Maximize or umaximize current tab.
CTRL + I
Corrects indentation.
CTRL + SHIFT + F
Formats code. You can make beautiful looking code out of a mess with this. It requires a bit of setup, but it is well worth it. You can find its settings under Window->Preferences->Java->Code style->Formatter
CTRL + J
Incremental search. Similar to the search in firefox, it shows you results as you type. Don't be surprised if when you hit this combination nothing happens - at the first glance. Just start typing and eclipse will move your cursor to the first occurence.
CTRL+SHIFT+G
Bind this to "Generate getters and setters". This is a "must have".
ALT+C
Bind this to SVN/CVS "Commit".
ALT+U
Bind this to SVN/CVS "Update".
yes, you can go Window - Preferencee - General - Keys and see all available shortcuts. Also you can reorder keys here.
Also you can read more about eclipse shortcuts here

Eclipse jump to next/previous marked occurrence

As was asked previously, Eclipse has the nice "mark occurences" feature, which shows all occurences of the selected variable or method.
But I don't know any shortcut for jumping to the next/previous occurence in the editor.
The shortcut ctrl+k is not working, it solely works in conjunction with "incremental find" (ctrl+j).
I'm using Eclipse Indigo. Is there any shortcut or other solution?
Edit:
The answers and comments in the question linked above are now pretty exhaustive, I think.
It seems there is no all-in-one solution (at least for Java code editing):
I cant get Ctrl + (period) to work, at least in Java code where it finds the next problem. Even rebinding this to a different shortcut does not work.
Ctrl + K does text-based search only. If you want to find all occurrences of the variable i, it finds any letter i within any identifier and comment.
Renaming mode using Alt+Shift+R and then navigating through the occurrences using Tab and Shift+Tab comes close, but only works for identifiers you can actually rename for that source file. It does not work for library code (esp. JDK) for which no editable source is available.
Try Ctrl + , and Ctrl + .
Before that make sure you have checked Occurences in the small navigation dropdown:
You can change the key from Window -> Preferences -> keys:
It works for me.
You can find if your key bindings have changed by looking under Window -> Preferences -> General -> Keys and look for the command Find Next. You will see the binding in the column Binding and can also check if it's conflicting with something else in the list titled Conflicts: at bottom right corner of the dialog.

Eclipse keyboard shortcut: goto function name

Suppose I know a function name, but I don't know which file it's declared in. What Eclipse keyboard shortcut can take me to the function I'm looking for?
What I'm looking for is similar to Eclipse's:
Ctrl + Shift + R
except it will search for method names instead.
Sidenote
With Visual Assist X, I can do this by using the "Find Symbol" feature, which is executed with:
Shift + Alt + S
This is an old question, but for the sake of people Googling this, Ctrl + O opens the code outline search, which is what you were looking for.
Yeah, this is an old question, but I have a better solution: what about F3?
And CTRL + O is what Windows users are looking for.
Not exactly a direct shortcut, but you need to go through the Java Search dialog:
(Ctrl+H):
(Sergei mentions in the comments that you might have to select "Declarations" in the "Limit To" section)
Not sure if this is exactly what you want, but if you Ctrl + H, that'll bring up the search dialog. The default option (for me, using the Java EE perspective) is a Java search. I can type in the method name, and then select the 'Method' radio button under the Search For block. Note that the default option (again, for me) for the 'Limit To' block was the 'References' radio button. I had to change that to 'All occurences' in order to see the method declaration, and not just callers.
Press CTRL + Left Mouse Button on the name your function. Eclipse will open the clicked file with this function automatically.
I use Momentics, so I'm not sure if this is in Eclipse or in Momentics plugin, but if it is Eclipse I think this is exactly what you need: CTRL + Shift + T.
Quick and dirty is to use Ctrl+Shift+Up/Down, which jumps between members (methods, variables) in Java.
If the method in question is on an interface, then using Quick Outline or F3 to jump to the definition will only take you to the interface definition. This isn't often what I want. Instead I hit, on my mac, Cmd + T on the method to get a Quick Type Hierarchy. From the type hierarchy you can go to the implementation of the method.
Simply hitting F3 by placing cursor on the function name will work for windows users.
simple 2 ways to function declarations:
Way 1: ( Whole workspace )
Ctrl + Left Click the function calling place.
way 2: ( within the same page )
press Ctrl + F to find dialog window and type n function_name and search.
these will redirect to function definition

What's the trick to write code faster in Eclipse?

I know there is a trick that when you type quickly code in Eclipse, you can hit some secret keys and it will auto-complete the missing parts. Who knows them?
example: I have someVeryLongVariablesWhichIWantToTypeFast and I start typing someVeryLongVa but nothing happens. Only when I type method names a yellow box appears that wants to help me.
Ctrl + Space is the autocomplete shortcut
All shortcuts you can find under Window -> Preferences -> General -> Keys
As mentioned the command is Ctrl+Space to auto complete.
You can speed it up using camelCase...so in your example:
someVeryLongVariablesWhichIWantToTypeFast
you could start typing sVL then Ctrl+Space should auto complete or list all variables that match.
CamelCase also works for specify classes, searching for classes etc.
Others I like/use:
type sysCtrl+Space to get System.out.println statement (or err)
type foreCtrl+Space after an array/list line to foreach it
Click on an argument to a method and Ctrl+1 to create a field for it and assign it, great for constructors
Ctrl+1 on any local variable to convert to field, split declaration, or inline it
if you have
object.method().method2().method3()
selecting object.method() and type Ctrl+1 to assign to a field or local variable, then you get
Object objLocal=object.method()
objLocal.method2().method3()
//Can now select objLocal.method2() and do the same again
My favourites:
Ctrl + Space - auto complete
Ctrl + 1 - show quick fix options when you are over an error / warning
Shift + Ctrl + L - list short cuts
One trick that I love in Eclipse for Java is writing backwards (meaning you write the client before the code it calls). We typically think of autocomplete to help us with methods and variables that already exist. This is okay, but even cooler is when a method/class does not exist.
Try typing this code into a method (anywhere, really):
Who who = new Who();
who.whatUpMan("hi", 32);
Now left-click on the Who at the beginning. It will give you the choice to create a class, interface, enum, etc.
Now left-click on the whatUpMan. It will prompt you to create the method with the right parameter types and everything.
These are called "Quick Fixes" in Eclipse and they give you total freedom to code from the client "backwards" to classes it utilizes. And when you've already got the method, of course, control-space and control-shift-space (to see parameters for methods) are your friends.
http://eclipse-tools.sourceforge.net/EclipseEmacsKeybindings_3_1.pdf
Some more time savers that don't seem to be mentioned:
Ctrl+3 'Quick Access' which basically let's you reach anything without clicking around too much. E.g. type 'nav' in the popup dialog, rather than Window | Show View | General | Navigator or wherever it is.
Ctrl+O 'Quick Outline': when editing Java (and some other things), pops up a lighweight dialog so that you find anything in the file by a few keystrokes
Shift+Alt+T 'Refactoring', and things below that menu - look for shortcuts there, use 'Rename', 'Move', 'Extract method', 'Change method signature' often
Alt+Up/Down move blocks of code up/down without cut/paste
Alt+Shift+Up/Down select various levels of code (expressions,statements, methods, class) easily
Ctrl+1 on the selected code offers you cool stuff eg. Extract to variable/constant/method; Split variable declaration -- see others above, or just try it on anything
Ctrl+Shift+R find any file in the workspace, similar to Ctrl+Shift+T to find types
Ctrl + Shift + O : resolve all dependances automaticall. In Java, it's a life saver as it cleans old packages and add the required one without a single line to write.
"Right click" then "refactor" : all the features are handy, but I espacially love "rename" (Ctrl + Shift + R, c.f comments) because it will apply the changes to all the project. No more tricky find / replace wit regexp to do ensure you breal nothing else :-)
"Right click" then "source" : equally useful, with a special mention to "generate getter and setter" and "implement methods"
Ctrl + D : delete a line. Kinda cool.
I kind of remember CTRL+SPACE was the shortcut for autocomplete.
Another time-saver is formatting the code automatically using Ctrl + Shift + F.
Formatter preferences http://img187.imageshack.us/img187/5866/eclipseformatter.png
General Eclipse tips
Get rid of all the crap that you'll never use
if you do web-dev ... install the database, php, pydev, modules and plugins
install svn/cvs/git plugin
use Trac
have different code enviornments for different code types, i.e. one for python-dev, c++, and so on.
wait a few weeks to months before updating
i have about 100 premade mini scripts that i use frequently.
learn to develop your own plugins, as it's easy and fun.
For some applications, the answer is to generate the code using EMF. But the EMF learning curve is significant.
I would suggest go to Eclipse -> Preferences -> General -> Editor -> Keys and to configure your own keyboard shortcuts for all common tasks so that you can have custom keybindings that are perfect for you.
Probably this might not exactly answer your question but it is very relevant to your question title.
You can define templates in Eclipse to magically type and get a bunch of code typed for you. For instance you may type something like syso or sout to get System.out.println() in your Java code.
This can be done by following Window -> Preferences -> Java -> Editor -> Templates. You can also add a Template View, which you find at Window -> Show View -> Other -> Search for Templates.
Here is an image to clarify
* Original related answer in here as well.
Hope it is helpful to someone :)

What is the [shortcut/other way] for go to definition in Eclipse+Pydev

I used to use WingIde, where in a shortcut(f4, default) which I used quite often was Goto definition, which will open the definition file, and take me to it. Is there a similar shortcut for eclipse+pydev?
For Aptana Pydev, you have "Go To Definition": F3
(Andrew Falanga comments below that Alt+← allows you to return to the point you left)
The 'go to definition' actions enables you to get to a given definition.
It works well on 'self' tokens
It can work on methods / attributes from parameters (as the image below shows).
As others answered, F3 is the way to go, but going a bit further, you might also want to take a look at ctrl+shift+t to browse all the tokens available and ctrl+shift+r to browse all the files.
Assuming you mean "go to where a method/class/variable" is defined, in Eclipse, it is F3
Although the question is pretty time-barred, maybe this more general approach will help others looking for specific short-cuts in eclipse.
Help - Key Assist... opens a list of all available short-cuts, alphabetically sorted by description. ("Open Declaration" was the one looked for here.)
Window - Preferences - General - Keys lets you edit the short-cuts.
Actually it does not work when you set MSVC scheme. In eclipse mars go to
Windows->preferences then go to General->keys (or in type filter text type keys) then in Keys in type filter text type definition. Then you shall see in command below Python Go To Definition. In Binding text edit you can then set any shortcut you want.