views:

144

answers:

3

So I've written some code of an assignment and i forgot the universities polocy of indent with 2spaces.

Normally I'ld have put a: vim: ts=2:tw=2: et:

at the top of my files, but this time i forgot.

How should I go about replacing all tabs with 2 space? would s// work? (repalcing and with the respectiove characters.

A: 

How should I go about replacing all tabs with 2 space?

You can do

:%s/\t/  /g
codaddict
+7  A: 

You should have a look at retab. First set tabstop, shiftwidth and expandtab, then use the retab command: it will reformat all your file with the desired format.

tonio
Watch for literal tabs that are not indenting, that is, are not at the beginning of line. From :h :retab"Careful: This command modifies any <Tab> characters inside of strings". It means that "\tFoo\tBar" becomes " Foo Bar"
Heikki Naski
I fround oput that if i just add the vim setting stuff the the to, the when i reopen the file, vim will automatically call retab even.Thankyou
Oxinabox
A: 

Run the following commands:

:set expandtab tabstop=2 shiftwidth=2 softtabstop=2
:retab!

Check out my screencast on tidying whitespace here: http://vimcasts.org/episodes/tidying-whitespace/.

nelstrom