Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tabs and spaces conversion

I would like to automatically convert between tabs and spaces for indentation when I commit/update code to/from our repository. I have found the AnyEdit plugin for eclipse, which can convert directories of files. Not bad for a start, but does anybody have more expierience on how to handle this? Or maybe know of an Ant script or something else?

like image 884
Robse Avatar asked Sep 19 '08 08:09

Robse


People also ask

Is tab equal to 4 spaces?

Generally, a tab is the same width as 4 to 5 spaces provided the font being used equally sizes each character. For example, the Courier font's tab equals 5 spaces, whereas the Arial font is 11 spaces to each tab when the font size for both is set to 12.

What command is used to convert tabs to spaces?

To convert tabs in a text file to spaces, you can use the expand command. To convert each tab to a single space character, use the -t 1 option.

How do I change the space between tab spaces in Word?

On the HOME tab on the Ribbon, choose Replace from the Editing group (or press [Ctrl]+H) to open the Find And Replace dialog box. In the Find What field, enter one space character and the following characters, exactly as shown in red: {2,} In the Replace With field, enter ^t. Click the More button.


2 Answers

  1. Make sure you have your editor set to use spaces instead of tabs.
  2. Select all text and hit CMD + I on mac or CTRL + I on windows.
like image 120
pwaterz Avatar answered Oct 15 '22 04:10

pwaterz


Why not just use the code formatter and/or cleanup function? It has settings that take care of that stuff for you. You can even have it run automatically on save.

Edit: As Peter Perháč points out in the comments, this only answers half the question. I don't have any practical experience, but you could try the Maven Eclipse Format Plugin to format from a Maven build.

Unfortunately, that's Maven only, and I know of no light-weight command line formatter. But if you happen to use Maven, you can bind the format goal to the proper phase, and if you set Eclipse to auto-build, it would format on update.

Depending on the SCM tool (git, svn, etc), you could also create a hook that runs the build (but it might be a bit too heavy-weight for that).

like image 21
Sietse Avatar answered Oct 15 '22 04:10

Sietse