One of the (by me) most used and least hidden feature of both ReSharper and Eclipse is the Quick Fix, which I covered in the last post.
There's also a couple of handy keyboard shortcuts when it comes to navigating code, auto-generating code and renaming classes, files, variables etc.
But let's talk about keyboard mappings in ReSharper. You have two options: Either you use the Visual Studio scheme, or you use the IntelliJ IDEA scheme. The Visual Studio scheme lets you use a lot of the default settings from Visual Studio (but mapped to ReSharper commands, if available) while the IntelliJ IDEA scheme maps keyboard shortcuts to fit a lot of the features found in Jetbrain's Java IDE (IntelliJ IDEA).
Until today, I had never even tried the IntelliJ IDE (I actually downloaded it today just to see how efficiently I could use it after being accustomed to the ReSharper keymapping). With ReSharper, I played around a bit with both the VS-scheme and the IDEA-scheme and found the IDEA-scheme a lot simpler to use.
However, when doing a clean install av VS 2010 and ReSharper 6.1, I found a small bug. At least one Visual Studio shortcut doesn't get overridden the way it should. Annoyingly enough, this is the shortcut called "Go to declaration", which I use all the time. In IntelliJ, this is bound to CTRL+B, but Visual Studio waits for a keyboard chord instead. Since the default Visual Studio shortcut for this (F12) gets overridden by another ReSharper feature all together, you more or less lose the feature entirely.
Apparently, I'm not the only one who encountered this, and a bug ticket was already filed (and now, assigned too):
Luckily, it's a simple fix. I discovered this by a fluke when importing a new color theme for Visual Studio. Simply do the following:
- Select Tools -> Import/Export -> Export selected environments settings and save the settings file.
- Select Tools -> Import/Export -> Import selected environments settings.
- Select the option to just import and overwrite your current settings.
- Select the file you just exported.
This seems to do the trick, and CTRL+B works again. This bug doesn't seem to happen when updating from an older version (according to some of the comments on YouTrack).
2. Some useful keyboard shortcuts
So, using the IntelliJ scheme in ReSharper, and the default settings in Eclipse, here are some really useful features:
Navigation: Go to declaration (ReSharper) / Open declaration (Eclipse)
Does exactly what it sounds like - Opens the declaration. For instance, selecting this with the cursor over a class name opens the file containing the class and puts your cursor at the class declaration. With the IntelliJ shortcut, this is bound to CTRL+B while Eclipse uses the F3 key.
Renaming options: Variables and class names
Quite useful in order to rename your variables, class names and file names throughout your project. Eclipse has a somewhat clumsy way of doing this since it basically separates this into two features. The first one is called Rename in file an renames instance names, class names etc. in the current file only. The shortcut is a keyboard chord: CTRL+2, R. The other feature is Rename in workspace, which replaces all instances of the name in the entire workspace. The shortcut for this one is ALT+SHIFT+R. Both of them are also available through the quick fix (which I tend to use here instead)
In ReSharper, this is more or less baked together into one command: F2
For me, using F2 makes a lot of sense, since this is the usual "renaming" shortcut. It's used in a lot of file explorers such as MS Explorer in Windows, but also Dolphin and Nautilus (for the KDE and Gnome desktop environments, respectively). However, since Eclipse supports the option to change individual bindings, you could basically just do this. You could also change your layout completely. As in ReSharper, Eclipse supports multiple schemes. For instance, you could use schemes similar to the EMacs Text Editor.
Renaming options: Files
Eclipse and Resharper both have some really good renaming features when it comes to renaming files. For instance, a lot of times you'll want to rename a file after renaming a class. This is especially true when doing Java, since Java demands that a .java file contains one and only one class/interface (inner classes excepted). But more often than not, you'll want to at least follow this convention in .NET too (Yes, I know that there are cases where it's logical to group several classes into one file).
In ReSharper, you can of course use the F2 key, and in Eclipse, the ALT+SHIFT+R key, both described above. But you have options. In both environments, you could just simply change the class name directly in the source and use the quick fix to apply the refactoring. For instance, suppose I want to rename a class in Eclipse from
The same holds in VS+ReSharper, sans the compile error. If I try to rename a class from StrCalcTest to StrCalcTester, I get the following quick fix:
3. Final thoughts
So, I'm not going to try and answer the question of "which one is better" here, since both environments pretty much do what they are supposed to do. However, I thought that a small map of how the shortcuts in Eclipse and ReSharper relate could be of use. I'll try to include an updated version of this list in the end of every post from now on.
Navigation: Go to declaration (ReSharper) / Open declaration (Eclipse)
Does exactly what it sounds like - Opens the declaration. For instance, selecting this with the cursor over a class name opens the file containing the class and puts your cursor at the class declaration. With the IntelliJ shortcut, this is bound to CTRL+B while Eclipse uses the F3 key.
Renaming options: Variables and class names
Quite useful in order to rename your variables, class names and file names throughout your project. Eclipse has a somewhat clumsy way of doing this since it basically separates this into two features. The first one is called Rename in file an renames instance names, class names etc. in the current file only. The shortcut is a keyboard chord: CTRL+2, R. The other feature is Rename in workspace, which replaces all instances of the name in the entire workspace. The shortcut for this one is ALT+SHIFT+R. Both of them are also available through the quick fix (which I tend to use here instead)
In ReSharper, this is more or less baked together into one command: F2
For me, using F2 makes a lot of sense, since this is the usual "renaming" shortcut. It's used in a lot of file explorers such as MS Explorer in Windows, but also Dolphin and Nautilus (for the KDE and Gnome desktop environments, respectively). However, since Eclipse supports the option to change individual bindings, you could basically just do this. You could also change your layout completely. As in ReSharper, Eclipse supports multiple schemes. For instance, you could use schemes similar to the EMacs Text Editor.
Renaming options: Files
Eclipse and Resharper both have some really good renaming features when it comes to renaming files. For instance, a lot of times you'll want to rename a file after renaming a class. This is especially true when doing Java, since Java demands that a .java file contains one and only one class/interface (inner classes excepted). But more often than not, you'll want to at least follow this convention in .NET too (Yes, I know that there are cases where it's logical to group several classes into one file).
In ReSharper, you can of course use the F2 key, and in Eclipse, the ALT+SHIFT+R key, both described above. But you have options. In both environments, you could just simply change the class name directly in the source and use the quick fix to apply the refactoring. For instance, suppose I want to rename a class in Eclipse from
TestProject
to MyTestProject
. This will immediately cause a compile error, but also trigger a quick fix renaming option, as seen in figure 1:Figure 1: Renaming via the Eclipse quick fix |
The same holds in VS+ReSharper, sans the compile error. If I try to rename a class from StrCalcTest to StrCalcTester, I get the following quick fix:
Figure 2: Renaming via the ReSharper quick fix - And yes: I finally have a dark theme for VS! |
3. Final thoughts
So, I'm not going to try and answer the question of "which one is better" here, since both environments pretty much do what they are supposed to do. However, I thought that a small map of how the shortcuts in Eclipse and ReSharper relate could be of use. I'll try to include an updated version of this list in the end of every post from now on.
Functionality | Eclipse | ReSharper |
Go to declaration | F3 | Ctrl+B |
Rename in file | Ctrl+2, R | F2 |
Rename everywhere | Alt+Shift+R | F2 |
Hopefully, I'll be able to build a large comprehensive list of commands over time.
4. What's next?
I'm thinking TDD: How well does ReSharper VS Eclipse integrate with test tools such as NUnit and JUnit, respectively? Do we have any useful shortcuts or other information that could simplify things for us?
... I'm aware of a few, but I'm definitely going to find out more about it until I post again.
No comments:
Post a Comment