0% found this document useful (0 votes)
31 views6 pages

Eclipse Shortcuts

Uploaded by

Nikita Chauhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views6 pages

Eclipse Shortcuts

Uploaded by

Nikita Chauhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Organize Imports (Ctrl + Shift + O)


To use a class in Java, you need to import it or the package it belongs to. Eclipse uses
this import to validate your code and provide auto-completion (real-time typing
suggestions).

But who has time to memorize every single package path for every single class in every
single library? You can let Eclipse handle it for you using the Ctrl + Shift + O shortcut,
which automatically imports unrecognized classes in code.

For example, if you have this bit of code:

import java.util.ArrayList; // this line will be added


public class Hello {
public static void main(String[] args) {
ArrayList list = new ArrayList();
}
}

Note: This shortcut also removes unused imports (in cases where you deleted code)
and sorts the import statements by package.

2. Correct Indentation (Ctrl + I)


Code readability is important—when you’re reading your own code at a later date, or
when somebody else.

Poor indentation is one of the most common programming mistakes people make in a
hurry. In layman's terms, indentation means the blank or empty space at the start of a
code line.

Does your code often look like this?

public void insertHead(int x) {


Link newLink = new Link(x);
if (isEmpty())
tail = newLink;
else
head.previous = newLink;
newLink.next = head;
head = newLink;
}

Maybe you wrote it that way, or maybe you copy-pasted it from elsewhere. Either way,
the good news is that Eclipse makes it trivially easy to fix. Highlight the code that you
want to clean up, then use the Ctrl + I shortcut to instantly bring it to proper indentation.

You can use Ctrl + A to select the entire file, and then use this shortcut to quickly fix all
the indentation.

public void insertHead(int x) {


Link newLink = new Link(x);
if (isEmpty())
tail = newLink;
else
head.previous = newLink;
newLink.next = head;
head = newLink;
}

You can also change how Eclipse handles indentation by going to Window >
Preferences, then in the left panel, navigate to Java > Code Style > Formatter >
Edit... > Indentation.

3. Delete Current Line (Ctrl + D)


When you start learning Java it's natural to delete entire lines of code at a time. The
worst way to do this? Highlight with the mouse and then hit Backspace. The rookie way
to do this? Hit the End key, hold Shift, hit the Home key, then Backspace.

But what about the pro way? You just need to put your mouse cursor on the line and
then press Ctrl + D to delete it in one go.

4. Autocomplete Recommendation (Ctrl + Space)


Java is unfortunately known for being extremely verbose. The names of classes,
methods, and variables are some of the longest in the entire programming industry.
Typing them all by hand every single time? Not our idea of a fun time.

Here's what you do instead:

1. Type the first few letters of the class, method, or variable you want.
2. Then hit the Ctrl + Space key combination. This brings up a list of autocomplete
recommendations along with method signatures, variable types, and more.
3. Select the recommendation you want to apply, hit the Enter key, and keep
coding.

Things like Eclipse autocomplete shortcuts are some of the reasons why IDEs trump
text editors. As newbie-friendly as Eclipse's interface is, you owe it to yourself to learn
such keyboard shortcuts. They'll boost your productivity even further, guaranteed.

5. System.out.println ("sysout" and Ctrl + Space)


When working with console applications, you'll need to use System.out.println() for
printing messages. But because this is so cumbersome, there's a quick shortcut for
System.out.println() in eclipse: type "sysout" (without the quotes), then hit Ctrl +
Space.

The best part? The cursor is immediately placed within the method call's parentheses,
so you can start typing the message right away.

6. Search Entire Project (Ctrl + H)


When working on large codebases, it's easy to forget where you declared certain
classes, methods, or variables. Instead of wasting time combing through directories by
hand, use the Search Entire Project prompt with the Ctrl + H shortcut.
By default, it comes with three search types: File Search, Git Search, and Java Search.
You'll mostly use Java Search, which only searches through source files, but the other
two can be useful in their own ways.

7. Run Application (Ctrl + F11)


The first time you run a new project, you should do it through Run > Run As... > Java
Application. But after that, you can speed things up with the Ctrl + F11 shortcut. This
runs the current project using the same configuration as the last time you ran it.

8. Rename (Alt + Shift + R)


Here's the thing about class, method, and variable names: your code might contain
references to them many, many times. Now imagine if you ever needed to change the
name of a class, method, or variable. It could take hours (or even days) to rename
every single reference.

One of Eclipse’s most useful features is its keybindings/shortcuts, which make coding
easier and faster. Here’re some of the most useful Eclipse shortcuts for Java
developers.

1. Change case: If you have some text in lowercase and want to change it to
uppercase, simply highlight it and hit Ctrl Shift X; for vice-versa, click Ctrl Shift
Y.

2. Autocomplete: If you want to print something in Java, you can type


“System.out.println” and click Ctrl + Space. The Eclipse will automatically
complete the code and put the cursor in between the two parentheses; here, you
can fill in the content you want to print.

3. Main Method: Enter “main” and press Ctrl + Space; the first proposal will be the
primary technique choice. With this Eclipse shortcut, you can write the main
method with only a few keystrokes.

4. Loops: Simply write the loop (for example, “for,” “while,” or “do”) and press Ctrl +
Space. The Eclipse will present you with many loop options from which you can
select one and enter the conditions.
5. Conditional statements: In Eclipse, constructing an if statement is as simple as
starting a loop. Enter “if” and press Ctrl + Space. Select the conditional
statement from the options presented.

6. Try-Catch block: Eclipse makes surrounding your code with a try-catch block
easy. Simply choose the code covered by a try-catch and press Alt Shift Z;
many alternatives will show up for enclosing the code, including a try-catch block.

Eclipse Shortcuts for code editing

Whether you want to comment out code or jump to a particular line rapidly,
these Eclipse shortcuts for windows will make your code editing smooth.

1. Use Ctrl + / for commenting, uncommenting lines, and blocks


2. Ctrl + Shift + / shortcut is used for commenting and uncommenting lines with
block comments.
3. Alt + ↑ + R for renaming class, variable, method (function), etc.

To format your code

1. Select text, then Ctrl + Shift + F for formatting.


2. Selecting class and press F4 to see its Type hierarchy

To handle the files

1. You can use Ctrl + F4 or Ctrl + w to close the current file


2. Click Ctrl + Shift + W to close all files.
3. Ctrl + F to find/replace in file
4. Ctrl + H to find and replace in file, project, or directory.

To migrate in-between lines

1. Go to the line (line number): Ctrl + L


2. To delete the line: Ctrl + D
3. Press Ctrl + Q to go to the last edited place
4. You can quickly shift a line or numerous lines of code up or down in your
application. Simply move the line by using Alt + up or down arrows. (This
allows you to place the code anywhere you wish in your software.)

Shortcuts for quick navigation in Eclipse

Navigate through the Eclipse environment with ease using these Eclipse shortcut keys.
These shortcuts will navigate you in a jiffy from switching between editors to jumping to
a specific feature/location.
1. Ctrl + 3: Quick access to any menu item or feature in Eclipse
2. Ctrl + Shift + T: Open a type quickly
3. Open a resource (e.g., file, image): Ctrl + Shift + R.
4. Ctrl + O: Quickly navigate to a method in the current class
5. Ctrl + 1: Shows available code actions and quick fixes
6. Quickly navigate to the superclass or implemented interface of the current type
with Ctrl + T.
7. Ctrl + Shift + L: Used for “Show Key assist,” previously used for Quicksearch
8. Ctrl + Q: Quick navigation to the last edit location (last edited line).

Also, read Best VS Code Shortcuts and Productivity Hacks for 2023

Eclipse shortcuts for debugging

Debugging can be time-consuming, but with these Eclipse shortcuts, you can streamline
the process and get to the root of the issue quickly.

Debug mode

1. F5 (Step into): This allows you to enter debug mode.


2. F6 (Step over): This assists in moving to the next line without leaving debug
mode.
3. F7 (Step out): This allows you to step out/return to the current method/caller in
debug mode.
4. F8 (Resume execution): This allows you to continue executing the program
without stopping debugging.
5. F9 (Toggle breakpoint): This allows you to set or remove a breakpoint on the
current line of code. A breakpoint will cause the program to stop executing and
enter debug mode.

Application debugging

1. Ctrl + F11: Use this to run the last application opened.


2. F11: Run the program in debug mode, where you can step through the code and
inspect variables.

Show Perspectives

1. Ctrl + Shift + B: This opens the Breakpoints view, which displays all the
breakpoints set in your workspace.
2. Ctrl + Alt + R: This opens the Debug Perspective, a special view that provides
tools and information specifically for debugging.
3. Ctrl + ↑ + I: Inspect the value of a variable during debugging.

You might also like