SQUARISM addicted to pixels

Strip off tabs in vim

Posted on September 22, 2005

When you paste a block of text into a Putty window, many times you'll get an increasing number of leading tabs. Not so if you use gnome-terminal (IIRC). Quite annoying in a Windows world.

Strip tabs and spaces out from current position to the end of the file with:

:.,$s/^[<tab>]*\s*//

Or perhaps you only want a small block in the middle of the file changed. First, turn on line numbers.


:set number

Then search and replace on specific line numbers (in this example lines 15 through 41).

:15,41s/^[<tab>]*\s*//

Then use Ctrl-V (down arrow or h,j,k,l keys to select block) and hit ">" to re-indent. Works much better than reformatting by hand.

Filed under: Unix Leave a comment
Comments (2) Trackbacks (0)
  1. most of the time, highlighting the text in visual block mode and then pressing = works, too – it’ll be indented correctly afterwards.

  2. Phil76, I couldn’t get your tip to work on a bit of XML text. Does it only work in certain situations or when vi thinks you are working in a specific programming language?


Leave a comment


Trackbacks are disabled.