William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

change left-indent tab to white-space

vi : change left-indent tab to white-space

When we edit php stuff in a IDE (Integrated Developing Environment such as Dreamweaver, EClipse, and Aptana), We usually has problem with codes’ ‘left indent‘.

Almost all editor use tab(‘\t’) as left indent. The problem will occur when editing the codes in different editor, such as Dreamweaver, notepad+, and Aptana, etc. They explain the ‘left indent‘ by their own ways, and will make the codes actually not ‘left-indent‘ and confusion to read.

The good solution is to use ‘white space‘ instead of ‘left indent‘. Since white space is an ascii code, it makes the ‘left-indent’ solid and never changes across from different tools. To do it is pretty simple, the following is my way by using favorite vi in a *nix enviroment:

//1. using vi to edit a php file.
$ vi php_codes.php
//2. in vi, use sed:
:1,$s/\t/  /g
//if above doesn't work, use: 'ctrl-v', then 'ctrl-I' 
//instead of '\t' to try again.
//':set list' can get all hidden chars in vi.

This way will translate all left-indent tab (‘\t’) to white-spaces: 2 white-spaces, or 4, depending on your choice.

This will greatly increase the codes readability in different IDEs (Dreamweaver, EClipse, Zend, Aptana etc) since it use 2 white-spaces instead of tab (‘\t’).

A improvement way is to write a sed file to loop all php codes in a project, so the changes will apply to all files.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: