Technology TidBits

Answers to various technical questions on php programming, mysql, linux, and many more categories.



How can I remove leading whitespace in all lines in a file using vi?

Last updated: 07/03/2009
Add comment
Votes: 4
Comments: 0
Sometimes, when pasting copy into vi, it adds lots of tabs or spaces at the beginning of each line.  This makes things unreadable, and takes a long time to remove by hand.

This command will remove all leading "junk" from your HTML files.  NOTE:  Do not try this on any php or asp, or non-html file, as it will certainly trash the file. 

In vi, run this command:

:%s/^\s\s*//g


This will remove all leading characters up to the first < in the line.  Again, if you have embedded code in your file, do not use this - this is

Other questions in this category:
How do I set Tab stops in VI?
How can I turn on line numbering in Vi?
How can I jump to a line in the vi editor?
How can I remove DOS linebreaks (^M) from my files?
How can I delete a large chunk of text using vi?
How can I undo and redo changes in vi?
How can I search in the vi editor?



Powered by KnowledgebasePublisher 1.1
Superb Internet
Content provided by Roberts WebForge, Inc.