A friend told me that Eclipse doesn’t have a way to find and replace all a certain term in a workspace to something else. So, just in case anybody is thinking the same, I’m here to show differently.

At this time, I’m only going to provide the easiest methods to accomplish these tasks. This means using hotkeys (shortcuts) rather than using the mouse and menu. Hotkeys allow developers to be much more productive.

So, most people know about Ctrl+F for “Find”. In Eclipse, Ctrl+F is “Find/Replace”. Using this method, users may replace words in a single document only.

The fun, rarely-known, hotkey is Ctrl+H. This shortcut allows users to replace all values in all files, as defined by the user. Meaning, one could choose to only “Replace All” in all XML files only. Before having to commit to replace all values, Eclipse will show you exactly how many instances will be replaced and what files they are in. Depending on the file type you currently have active, Eclipse will have a different action. Below shows the simplest order of operations to achieve “Replace All in All Like Documents”.

For XML Files:

  1. Ctrl+C the text you want to do the replacing (if available)
  2. Highlight the text you want to be replaced
  3. Ctrl+H. Brings you to File Search. The selection from (2) will auto-fill the search box
  4. In the “File name patterns” input box, type in “*.xml”
  5. Click “Replace…”
  6. Ctrl+V (Paste). Or type in the value you want to do the replacing 
  7. Enter

 

For Java Files:

 

 

  1. Ctrl+C the text you want to do the replacing (if available)
  2. Highlight the text you want to be replaced
  3. Ctrl+H. Brings you to Java Search
  4. Click on the File Search tab on the far left. The selection from (2) will auto-fill the search box
  5. In the “File name patterns” input box, type in “*.java”
  6. Click “Replace…”
  7. Ctrl+V (Paste). Or type in the value you want to do the replacing 
  8. Enter

UPDATE: Right after I posted this, I remembered the ALT shortcut.

For Java Files:

  1. Ctrl+C the text you want to do the replacing (if available)
  2. Highlight the text you want to be replaced
  3. Tap ALT, then A, then F. Brings you to File Search. The selection from (2) will auto-fill the search box
  4. In the “File name patterns” input box, type in “*.java”
  5. Click “Replace…”
  6. Ctrl+V (Paste). Or type in the value you want to do the replacing 
  7. Enter

If you know a shorter or faster method, then please email me, explaining how. Then I will share it with everybody.

If you liked this post, then you may be interested in “How to Create a Hotkey to Double-Click”. http://anonsage.blogspot.com/2012/12/how-to-create-hotkey-to-double-click.html

 - Danial Goodwin -

 

DISCLAIMER: This How-To was done using “Eclipse for Mobile Developers”, Version: Juno Service Release 1, Build id: 20121004-1855.

DISCLAIMER: I will use explicitly write out “SHIFT” if a hotkey needs it. Ex: Ctrl+H means Ctrl+h. But, for clarity and neatness, I choose to use capital letters in the hotkeys.