Sunspots

The Sun, eclipses, auroras and space weather explained

Eclipses

Select All Occurrences of a Word in Eclipse

· 5 min read · Eclipses

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Selecting all occurrences of a word in Eclipse lets you see every place that word appears in the current file at a glance, and it's the first step toward multi-cursor editing or a quick find-and-replace. This guide shows you the fastest keyboard shortcuts and menu paths, plus how to avoid common pitfalls like accidentally selecting only part of a word.

What You'll Need

  • Eclipse IDE (any recent version, e.g., 2023-09 or later) with a Java or any text editor open.
  • A file with the word you want to select. The word must be a contiguous string of letters, digits, or underscores (no spaces or punctuation).
  • No special plugins required—this is built into the Eclipse text editor.

Step-by-Step

  1. Open the file containing the word you want to select. Make sure the editor is active (click inside it).
  2. Place the cursor anywhere inside the word you want to select. Do not double-click yet—just a single click to position the caret.
  3. Use the keyboard shortcut for your operating system:
    • Windows/Linux: Press Alt + Shift + Up Arrow (this is the default for “Select Next Occurrence”).
    • macOS: Press Option + Shift + Up Arrow.
    This selects the current word and then selects the next occurrence of that exact word in the file. Each press adds the next occurrence to the selection.
  4. Repeat the shortcut until you have selected all occurrences you want. If you want to select every single occurrence in the file, keep pressing until the selection stops growing (Eclipse will wrap around to the top).
  5. To select all occurrences at once (if you don't want to press repeatedly), use the menu: Edit → Find/Replace (or press Ctrl+F on Windows/Linux, Cmd+F on macOS). In the Find/Replace dialog, type the word, then click “Select All” (the button with a cursor icon). This selects every occurrence in the file immediately.
  6. Once selected, you can:
    • Type to replace all selected occurrences at once (multi-cursor editing).
    • Copy, cut, or delete them all together.
    • Use the selection as a starting point for a more complex refactoring.

Common Mistakes

  • Not placing the cursor inside the word: If the cursor is on a space or punctuation, Eclipse will select the next word from that point, not the word you intended.
  • Selecting part of a word: If you double-click to select a word, then use the shortcut, it might only match the selected substring (e.g., “cat” in “concatenate”). Always place a single cursor inside the word, not a selection.
  • Using the wrong shortcut: The default is Alt+Shift+Up, but some Eclipse distributions (like STS) may remap it. Check under Window → Preferences → General → Keys for “Select Next Occurrence”.
  • Forgetting that it’s case-sensitive: “Word” and “word” are treated as different. The shortcut matches exact case.

Tips

  • Use the Find/Replace dialog for a one-shot select-all: It’s faster if you need every occurrence without stepping through them.
  • Combine with multi-cursor editing: After selecting all occurrences, you can press Ctrl+Alt+Down (or Cmd+Alt+Down on macOS) to add a cursor at each selection, then edit them all simultaneously.
  • Use the “Word” selection mode: If you often need to select whole words, double-clicking selects the whole word, but the shortcut works on the word under the caret even without double-clicking.
  • Customize the shortcut: Go to Window → Preferences → General → Keys, search for “Select Next Occurrence”, and bind it to something more comfortable if the default doesn’t suit you.
  • Use it in any editor: This works in Java, XML, HTML, CSS, and other text editors within Eclipse, not just Java files.

Troubleshooting

  • The shortcut does nothing: Make sure the editor has focus (click inside the file). Also check that you haven’t changed the binding. If you’re on a laptop with a function key, you may need to press Fn + Alt + Shift + Up.
  • It selects the wrong word: The shortcut selects the “word” under the caret, which is defined by letters, digits, and underscores. If your word contains a hyphen (e.g., “well-known”), it will only select “well” or “known” depending on caret position. Use Find/Replace with “Whole Word” option instead.
  • It only selects one occurrence, not all: The shortcut is incremental—each press adds the next one. If you want all at once, use the Find/Replace dialog’s “Select All” button.
  • Select All button is grayed out: In the Find/Replace dialog, make sure you’ve typed the search string and that the editor has focus. If the dialog is floating, click inside the editor first, then back to the dialog.
  • Selection includes comments and strings: By default, the shortcut selects all occurrences, including those inside comments or string literals. If you want to avoid those, use a more targeted refactoring (like Rename) or use the “Search” view with scope filters.

Frequently Asked Questions

Does this work in all Eclipse editors?

Yes, the “Select Next Occurrence” feature is available in the generic text editor, so it works in Java, XML, HTML, CSS, JavaScript, and most other file types.

Can I select all occurrences of a word that appears in multiple files?

No, this feature works only within the current file. To find and select across multiple files, use Search → File (Ctrl+H) and then use the search results view to select matches individually.

Is there a way to select all occurrences without using the keyboard?

Yes, use Edit → Find/Replace, type the word, and click the “Select All” button. That selects all occurrences in the current file.

What if I want to select only whole words, not substrings?

The shortcut always selects whole words (based on word boundaries). If you use Find/Replace, check the “Whole Word” option to avoid matching substrings.

How do I deselect all occurrences after selecting them?

Press Esc or click anywhere in the editor to clear the selection. You can also press Alt+Shift+Down to deselect the last occurrence added.

Can I change the shortcut to something easier?

Yes, go to Window → Preferences → General → Keys, search for “Select Next Occurrence”, and bind a new key combination.