change left-indent tab to white-space
Blogs20112011-11-28
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.
