Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace spaces with tabs using Eclipse

I downloaded some code from the Internet, and the four-space indentation is bugging the crap out of me. I tried to do a find and replace for "<4 spaces>" and replace it with "\t", but that just replaced all sets of spaces with the string "\t". How would I put a tab in the "replace" box?

like image 511
Joshua Hyatt Avatar asked Mar 06 '14 01:03

Joshua Hyatt


People also ask

How do I get tabs in eclipse?

Ctrl + H > File Search tab.

Does Eclipse use tabs or spaces?

Eclipse - Tab to spaces And eclipse uses tabs for spaces by default. Tabs are always dependent on the environment and use 4 spaces in windows. If you use source code written with tab spaces, code is consistent across different environments.

How do you replace tabs with spaces in Java?

You can simply use this regular expression to replace any type of escapes( including tabs, newlines, spaces etc.) within a String with the desired one: lineOfText. replaceAll("\\s", " ");


1 Answers

  1. Open Window->Preferences from menu bar.
  2. Select Text Editors from tree menu.
  3. Uncheck Insert spaces for tabs.

enter image description here

After that, run Format menu from context menu and save the file:

enter image description here

like image 57
Kohei Mikami Avatar answered Sep 20 '22 13:09

Kohei Mikami