Tip #247: Preexisting code indentation
tip karma |
Rating 17/9, Viewed by 1049
|
created: |
|
May 17, 2002 0:46 |
|
complexity: |
|
basic |
author: |
|
Riccardo Casini |
|
as of Vim: |
|
5.7 |
Using tabs as elementary unit in your code indentation has two advantages: first, you may modify 'tabstop' and immediately all the indentations depths are modified according to it; second, your file will be smaller.
But how can we change some already-written code in order to convert spaces to tabs. Very simple!
Suppose your old code has an indentation unit of 2 spaces
:ret! 2
:x
will replace every 2-spaces to one tab, independently from your current tabstop value, and will save the modified file.
Then, if you open again the file with tabstop=2, the file will look as before but it will be smaller. If you open the file with tabstop=4, the code vill have a more indented look, and so on...
Cheers!
<<Working with Unicode (the same, rewritten for legibility) |
Auto-save the current buffer periodically. >>
Additional Notes
|