Eclipse
- Overview
- Editor window commands
- Run and debug
- Kill eclipse
- Helpful shortcuts - Manage Files and Projects - Editor Window - Navigate in Editor - Select Text - Edit Text - Search and Replace - Indentions and Comments - Editing Source Code - Code Information - Refactoring - Run and Debug - The Rest
- How to import an existing directory into Eclipse?
- Must have plugins for Eclipse
- Eclipse vs Spring Tool Suite
Overview
If Eclipse looks terrible with Linux themes, this is what you can do:
You should get a better display by doing this: in Eclipse, go to Window > Preferences > General > Appearance. Choose a dark theme for Eclipse and restart Eclipse. It should be in better harmony with your Linux distribution’s dark theme.
Toggle full screen (zen mode) : Alt + F11
If Terminal is not already installed in your Eclipse IDE,
you can install the TM Terminal from the Eclipse */release update site, as you can see in the image below.
To open the command prompt (shell or terminal) using the path of a project directory inside Eclipse, you just need to select the folder, and press Ctrl+Alt+T, or right-click and select Show In Local Terminal > Terminal.
Use CTRL-ALT-SHIFT-T to choose which type of Terminal to run.
How do you get Eclipse to auto-generate a main method in a new Java class? Type main and press ctrl+space.
Editor window commands
| Command | Description |
|---|---|
| Ctrl+M | Maximize or un-maximize current Editor Window (also works for other Windows) |
| Ctrl+Page Down/Ctrl+Page Up | Switch to next editor / switch to previous editor |
| Ctrl+E | Show list of open Editors. Use arrow keys and enter to switch |
| Ctrl+W | Close current file |
| Ctrl+Shift+W | Close all files |
Run and debug
Ctrl+F11 Save and launch application (run)
Kill eclipse
In Linux
You can use jps -l to get all of the process id’s of java processes
Check the pid of the process that is running Eclipse and copy the pid.
Then kill the process id by running: kill -9 {the_copied_pid}
Helpful shortcuts
Manage Files and Projects
| Command | Description |
|---|---|
| Ctrl+N | Create new project using the Wizard |
| Ctrl+Alt+N | Create new project, file, class, etc. |
| Alt+F, then . | Open project, file, etc. |
| Ctrl+Shift+R | Open Resource (file, folder or project) |
| Alt+Enter | Show and access file properties |
| Ctrl+S | Save current file |
| Ctrl+Shift+S | Save all files |
| Ctrl+W | Close current file |
| Ctrl+Shift+W | Close all files |
| F5 | Refresh content of selected element with local file system |
Editor Window
Focus/ cursor must be in Editor Window for these to work.
| Command | Description |
|---|---|
| F12 | Jump to Editor Window |
| Ctrl+Page Down/Ctrl+Page Up | Switch to next editor / switch to previous editor |
| Ctrl+M | Maximize or un-maximize current Editor Window (also works for other Windows) |
| Ctrl+E | Show list of open Editors. Use arrow keys and enter to switch |
| Ctrl+F6/Ctrl+Shift+F6 | Show list of open Editors. Similar to ctrl+e but switches immediately upon release of ctrl |
| Alt+Arrow Left/Alt+Arrow Right | Go to previous / go to next Editor Window |
| Alt+- | Open Editor Window Option menu |
| Ctrl+F10 | Show view menu (features available on left vertical bar: breakpoints, bookmarks, line numbers, …) |
| Ctrl+F10, then n | Show or hide line numbers |
| Ctrl+Shift+Q | Show or hide the diff column on the left (indicates changes since last save) |
| Ctrl+Shift++/- | Zoom text in/ out |
Navigate in Editor
| Command | Description |
|---|---|
| Home/End | Jump to beginning / jump to end of indention. Press home twice to jump to beginning of line |
| Ctrl+Home/End | Jump to beginning / jump to end of source |
| Ctrl+Arrow Right/Arrow Left | Jump one word to the left / one word to the right |
| Ctrl+Shift+Arrow Down/Arrow Up | Jump to previous / jump to next method |
| Ctrl+L | Jump to Line Number. To hide/show line numbers, press ctrl+F10 and select ‘Show Line Numbers’ |
| Ctrl+Q | Jump to last location edited |
| Ctrl+./Ctrl+, | Jump to next / jump to previous compiler syntax warning or error |
| Ctrl+Shift+P | With a bracket selected: jump to the matching closing or opening bracket |
| Ctrl+[+]/Ctrl+- on numeric keyboard | Collapse / Expand current method or class |
| Ctrl+[/]/Ctrl+* on numeric keyboard | Collapse / Expand all methods or classes |
| Ctrl+Arrow Down/Ctrl+Arrow Up | Scroll Editor without changing cursor position |
| Alt+Page Up/Alt+Page Down | Next Sub-Tab / Previous Sub-Tab |
Select Text
| Command | Description |
|---|---|
| Shift+Arrow Right/Arrow Left | Expand selection by one character to the left / to the right |
| Ctrl+Shift+Arrow Right/Arrow Left | Expand selection to next / previous word |
| Shift+Arrow Down/Arrow Up | Expand selection by one line down / one line up |
| Shift+End/Home | Expand selection to end / to beginning of line |
| Ctrl+A | Select all |
| Alt+Shift+Arrow Up | Expand selection to current element (e.g. current one-line expression or content within brackets) |
| Alt+Shift+Arrow Left/Arrow Right | Expand selection to next / previous element |
| Alt+Shift+Arrow Down | Reduce previously expanded selection by one step |
Edit Text
| Command | Description |
|---|---|
| Ctrl+C/Ctrl+X/Ctrl+V | Cut, copy and paste |
| Ctrl+Z | Undo last action |
| Ctrl+Y | Redo last (undone) action |
| Ctrl+D | Delete Line |
| Alt+Arrow Up/Arrow Down | Move current line or selection up or down |
| Ctrl+Alt+Arrow Up/Ctrl+Alt+Arrow Down/ | Duplicate current line or selection up or down |
| Ctrl+Delete | Delete next word |
| Ctrl+Backspace | Delete previous word |
| Shift+Enter | Enter line below current line |
| Shift+Ctrl+Enter | Enter line above current line |
| Insert | Switch between insert and overwrite mode |
| Shift+Ctrl+Y | Change selection to all lower case |
| Shift+Ctrl+X | Change selection to all upper case |
Search and Replace
| Command | Description |
|---|---|
| Ctrl+F | Open find and replace dialog |
| Ctrl+K/Ctrl+Shift+K | Find previous / find next occurrence of search term (close find window first) |
| Ctrl+H | Search Workspace (Java Search, Task Search, and File Search) |
| Ctrl+J/Ctrl+Shift+J | Incremental search forward / backwards. Type search term after pressing ctrl+j, there is now search window |
| Ctrl+Shift+O | Open a resource search dialog to find any class |
Indentions and Comments
| Command | Description |
|---|---|
| Tab/Shift+Tab | Increase / decrease indent of selected text |
| Ctrl+I | Correct indention of selected text or of current line |
| Ctrl+Shift+F | Autoformat all code in Editor using code formatter |
| Ctrl+/ | Comment / uncomment line or selection ( adds ‘//’ ) |
| Ctrl+Shift+/ | Add Block Comment around selection ( adds ‘… *’ ) |
| Ctrl+Shift+\ | Remove Block Comment |
| Alt+Shift+J | Add Element Comment ( adds ‘** … *’) |
Editing Source Code
| Command | Description |
|---|---|
| Ctrl+Space | Opens Content Assist (e.g. show available methods or field names) |
| Ctrl+1 | Open Quick Fix and Quick Assist |
| Alt+/ | Propose word completion (after typing at least one letter). Repeatedly press alt+/ until reaching correct name |
| Ctrl+Shift+Insert | Deactivate or activate Smart Insert Mode (automatic indention, automatic brackets, etc.) |
Code Information
| Command | Description |
|---|---|
| Ctrl+O | Show code outline / structure |
| F2 | Open class, method, or variable information (tooltip text) |
| F3 | Open Declaration: Jump to Declaration of selected class, method, or parameter |
| F4 | Open Type Hierarchy window for selected item |
| Ctrl+T | Show / open Quick Type Hierarchy for selected item |
| Ctrl+Shift+T | Open Type in Hierarchy |
| Ctrl+Alt+H | Open Call Hierarchy |
| Ctrl+Shift+U | Find occurrences of expression in current file |
| Ctrl+move over method | Open Declaration or Implementation |
Refactoring
| Command | Description |
|---|---|
| Alt+Shift+R | Rename selected element and all references |
| Alt+Shift+V | Move selected element to other class or file (With complete method or class selected) |
| Alt+Shift+C | Change method signature (with method name selected) |
| Alt+Shift+M | Extract selection to method |
| Alt+Shift+L | Extract local variable: Create and assigns a variable from a selected expression |
| Alt+Shift+I | Inline selected local variables, methods, or constants if possible (replaces variable with its declarations/ assignment and puts it directly into the statements) |
Run and Debug
| Command | Description |
|---|---|
| Ctrl+F11 | Save and launch application (run) |
| F11 | Debug |
| F5 | Step Into function |
| F6 | Next step (line by line) |
| F7 | Step out |
| F8 | Skip to next Breakpoint |
The Rest
| Command | Description |
|---|---|
| Ctrl+F7/Ctrl+Shift+F7 | Switch forward / backward between views (panels). Useful for switching back and forth between Package Explorer and Editor. |
| Ctrl+F8/Ctrl+Shift+F8 | Switch forward / backward between perspectives |
| Ctrl+P | |
| F1 | Open Eclipse Help |
| Shift+F10 | Show Context Menu right click with mouse |
How to import an existing directory into Eclipse?
There is no need to create a Java project and let unnecessary Java dependencies and libraries to cling into the project. The question is regarding importing an existing directory into eclipse
Suppose the directory is present in C:/harley/mydir. What you have to do is the following:
Create a new project (Right click on Project explorer, select New -> Project; from the wizard list, select General -> Project and click next.)
Give to the project the same name of your target directory (in this case mydir)
Uncheck Use default location and give the exact location, for example C:/harley/mydir
Click on Finish
You are done.
Must have plugins for Eclipse
https://marketplace.eclipse.org/content/spring-tools-4-aka-spring-tool-suite-4
How to run a custom maven command in Eclipse?
Run a custom maven command in Eclipse as follows:
- Right-click the maven project or pom.xml
- Expand Run As
- Select Maven Build…
- Set Goals to the command, such as:
clean install -Xorclean verify
Note: Eclipse prefixes the command with mvn automatically.
Eclipse vs Spring Tool Suite
STS seems to be a resource hog. It would hang up sometimes and take forever to recover. Installing custom plugins to Eclipse (including STS plugin in Eclipse) seems to be a much better way to go.