Replace spaces with tabs using Eclipse

Solution 1:

  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

Solution 2:

I figured it out. I just check the box that says "use regular expressions", then use \t.

Solution 3:

In answer to the second half of your question:

The reason why people like spaces more than tabs is consistency. If you have your editor set to show tabs as 4 spaces wide, and I have my editor set to show tabs as 8 spaces wide, the code we're writing will look different to each of us. That's okay until our mutual coworker forgets that we're using tabs and starts spacing his lines using 4 spaces. Now his code looks fine to you, but all the indentation is off to me.

Also, what happens when our work decides that lines should be 80 characters long, or 120 characters long? You'll happily code with 4 space tabs, and when it gets to my editor, I suddenly see some of your lines as too long.

Generally, it doesn't matter whether you use spaces or tabs, as long as you (and every person who works on your code) agrees on which to use, and how wide a tab character is.

I use 4 spaces everywhere, because it looks the same on every editor, every repository, when cated, and everywhere else.