For Java developers, they often use Eclipse or MyEclipse integrated development environment. Some practical Eclipse shortcut keys and usage tips can save a lot of time and improve work efficiency in daily development. Below, I will combine my own development experience to share with you the commonly used shortcut keys and tips in Eclipse.
15 Eclipse Common Development Shortcut Keys Usage Tips
1、alt+?oralt+/: Auto-complete code or prompt code
This is my favorite shortcut combination, especially when you type a few characters like "syso" and then easily press these two keys with two fingers, it automatically completes.System.out.println();and Eclipse by default shows.method hints. If the hint is interrupted and you want to see it again, you have to re-enter before the corresponding class or variable..only then can you see the hint again. However, if these two keys are used together, they can also provide hints. You can try it. Moreover, after typing "for", if there are local variables that need to be traversed above, a selection will pop up to usefor eachtraverse orfor(int;;)orwhile()and then automatically generate code.
2、ctrl+o: Quick outline view
If you want to view the methods of the current class or a specific method, but don't want to scroll the code up and down, and don't want to use the search function, then usectrl+oespecially when directly opening or tracking to a class with many methods, this is very useful. You can directly see what methods and member variables there are. It can list all methods and properties in the current class. You just need to enter the method name you want to query and clickenterto directly jump to the position you want.
3、ctrl+shift+r: Open resource list
This is probably the most time-saving shortcut combination of all, and I use it often. Especially when finding a file directly in a project or workspace by name, this set of shortcuts allows you to open any file in your workspace. You only need to press the first few letters of the file name or mask name, such as applic*.xml. The downside is that this set of shortcuts is not available in all views.
4、ctrl+shift+f: Format code
By default, it wraps at 80 characters, and this can be set. You can also reformat code according to code style settings. Our team has a unified code format, and we put it on our wiki. To do this, we open Eclipse, select Window Style, then set Code Formatter, Code Style, and Organize Imports. Use the Export function to generate configuration files. We put these configuration files on the wiki, and then everyone in the team imports them into their own Eclipse.
5、ctrl+e: Quickly switch editor
This set of shortcuts will help you browse among open editors, especially when many files are open.ctrl+eit will be more efficient and very helpful.
6、ctrl+page downorctrl+page up: Quickly switch between tabs
You can browse the previous and next tabs. If you are proficient, switching between pages will be very fast and feels great.
7、shift+enterandctrl+shift+enter: Create a blank line above or below the current line.
Shift+enterCreates a blank line below the current line, regardless of whether the cursor is at the end of the line.Ctrl+shift+enterThe other one inserts a blank line before the current line. These two shortcuts are also very helpful. At first you may not be used to them, but after using them many times, you will find it very convenient. Anyway, that's how I feel.
8、Alt+Up/Down Arrow keys: Swap contents of up/down lines or move current line up or down
This is also a time-saving magic tool. This combination moves the content of the current line up or down. Intry/catchpart, this shortcut works especially well.
9、Control+Alt+Up/Down Arrow keys: Copy highlighted line(s)
This is also a very useful shortcut. It can very conveniently copy the current code to the previous or next line. I also use it often.
10、ctrl+m: Maximize current editor window
Everyone knows that a large display screen can improve work efficiency.Ctrl+mIt is the shortcut to maximize the editor window. Press it again to restore the normal window.
11、ctrl+/: Automatically comment out current line or selected multiple lines
Automatically comment out the current line or multiple lines of code. Use//to comment, usectrl+\to uncomment.
12、ctrl+shift+/: Automatically comment out selected code block
Note that this uses/* */to comment (if it's programming language code). It is also very useful in development. HTML, CSS, etc. can also use this comment to generate corresponding comment tags. Usectrl+shift+\to uncomment.
13、ctrl+d: Delete current line
Delete the current line. This is very useful, and I use it often, especially when debugging and deleting the current error. Combined with Ctrl+Z, the edit undo shortcut, you can use it with ease.
14、ctrl+shift+xandctrl+shift+y: Toggle case of English letters
This shortcut is commonly used in writing SQL statements. I also use it often. It is recommended that keywords in SQL statements be in uppercase. Although the database is case-insensitive, this helps others and yourself read, especially when SQL statements are very long, and it also looks standardized.
15、ctrl+shift+o: Automatically import packages and remove unused packages
This shortcut is also very convenient. When we use a class from another package, if the corresponding package or class is not imported, a red wavy line prompt will appear. At this time, we can press this shortcut, and the red prompt will automatically disappear and return to normal. If there are multiple packages containing the same class, it will prompt you to choose. If there are unused packages that were imported, usually caused by copying code back and forth, you can also use this key to quickly remove them.
Here are some tips:
Lock the command line window: In the console view (Window -> Show View -> Other -> Basic -> Console), try using the scroll lock button to lock the console output and prevent it from scrolling.
Use the Ant view: In my Java or Debug mode, I like to show the Ant view so I can quickly run Ant tasks. You can find this view through Window > Ant. Put the Ant view in a corner of the screen, and add the build.xml file through the "Add Build Files (Add -> Other -> Show View -> Buildfiles)" button. In version 3.1, it even supports Ant debugging script language.
Automatically iterate over a collection: for + Control-Space: If you don't already know, you should remember that Control-Space is the auto-complete function. In Eclipse, you can also auto-complete structures. Within an array or collection scope, try typing "for" and then pressing the Control-Space key. Eclipse will ask you which collection you want to iterate over and then automatically complete the loop code.
Use hierarchical layout: In the Package Explorer view, the default layout (flat style) confuses me; it displays the full name of packages in the navigation tree. I prefer the view of my source packages and file system, which in Eclipse is called Hierarchical Layout. To switch to this mode, click the downward button in the Package Explorer view, choose Layout, and then select Hierarchical.
Display multiple files at once: You can browse multiple files at once. Drag an inactive editor window onto the scroll bar at the bottom or side of the active window to open it. That's the best way I can describe this trick.
Open two Eclipse instances at the same time: To merge changes from one CVS branch to another, I like to open two Eclipse instances with different workspaces at the same time. This way I can see all the changes by comparing with the latest version on CVS (right-click the project, then select Compare with Latest from HEAD) and then merge each change into the other CVS branch. The simplest way to launch multiple Eclipse instances is to use Eclipse with Launcher.
Implementors plugin: Install a plugin that can jump to an implementation of an interface. If you are a dependency injection fan, or are working based on well-designed interfaces, then you need such a plugin to speed up code navigation. You can find this plugin on SourceForge.
Automatically generate getter and setter methods: In the corresponding POJO, right-click a blank area, select 【Source】, then select 【Generate Getters and Setters】, then choose which properties you want to generate such methods for, click 【OK】 and it's done. Especially when there are many member variables, it saves a lot of time.
Attached is a complete list of Eclipse shortcut keys:
- Ctrl+1:Quick fix (the most classic shortcut, no need to explain)
- Ctrl+D:Delete current line
- Ctrl+Alt+↓:Copy current line to next line (copy and add)
- Ctrl+Alt+↑:Copy current line to previous line (copy and add)
- Alt+↓:Swap current line with the line below (especially practical, saves cutting and pasting first)
- Alt+↑:Swap current line with the line above (same as above)
- Alt+←:Previous edited page
- Alt+→:Next edited page (of course, relative to the previous one)
- Alt+Enter:Show properties of the currently selected resource (project, or file, or file)
- Shift+Enter:Insert a blank line below the current line (the mouse can be anywhere on the current line, not necessarily at the end)
- Shift+Ctrl+Enter:Insert a blank line above the current line (same principle as above)
- Ctrl+Q:Navigate to the last edited location
- Ctrl+L:Navigate to a specific line (a blessing for those whose programs exceed 100 lines)
- Ctrl+M:Maximize the current Edit or View (press again to restore)
- Ctrl+/:Comment the current line; press again to uncomment
- Ctrl+O:Quickly display Outline
- Ctrl+T:Quickly display the inheritance hierarchy of the current class
- Ctrl+W:Close the current Editor
- Ctrl+K:Quickly locate to the next occurrence of the selected word
- Ctrl+E:Quickly display the dropdown list of the current Editor (if not shown on the current page, it is displayed in bold)
- Ctrl+/(numpad):Collapse all code in the current class
- Ctrl+×(numpad):Expand all code in the current class
- Ctrl+Space:Code assistant completes insertion of some code (but it usually conflicts with the input method; you can modify the input method hotkeys, or temporarily use Alt+/ instead)
- Ctrl+Shift+E:Show the manager that manages all currently opened Views (you can select close, activate, etc.)
- Ctrl+J:Forward incremental search (after pressing Ctrl+J, each letter you type provides quick matching to locate a word; if not found, it shows "not found" in the status line. Especially useful when searching for a word. This feature existed in Idea two years ago)
- Ctrl+Shift+J:Reverse incremental search (same as above, but searches from back to front)
- Ctrl+Shift+F4:Close all open Editors
- Ctrl+Shift+X:Convert all selected text to lowercase
- Ctrl+Shift+Y:Convert all selected text to lowercase
- Ctrl+Shift+F:Format the current code
- Ctrl+Shift+P:Locate the corresponding matching character (e.g. {}) (when locating from front to back, the cursor must be inside the matching character; from back to front, the opposite)
The following shortcuts are commonly used in refactoring. I have organized the ones I personally like and use often (note: refactoring shortcuts generally start with Alt+Shift)
- Alt+Shift+R:Rename (this is one of my favorites, especially renaming variables and classes; it saves much more labor than manual methods)
- Alt+Shift+M:Extract method (this is one of the most commonly used refactoring methods, especially useful for large chunks of messy code)
- Alt+Shift+C:Modify method structure (quite practical; when there are N functions calling this method, one modification fixes it all)
- Alt+Shift+L:Extract local variable (you can directly extract some magic numbers and strings into a variable, especially when called in multiple places)
- Alt+Shift+F:Convert a local variable in a Class into a field variable (a quite practical feature)
- Alt+Shift+I:Inline variable (it may be inappropriate to say "merge variable"; Inline)
- Alt+Shift+V:Move function and variable (not commonly used)
- Alt+Shift+Z:Undo for refactoring (Undo)
Author: Java My Life (Chen Laixing)
Original source: http://blog.csdn.net/chenleixing/article/details/44600587