Frames Catherine White
Frames Catherine White

Reputation: 28242

Vim replacing tabs with double spaces

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

Normally I'ld have put a: //vim: ts=2:tw=78: 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/[TAB]/[SPACE][SPACE] work? (replacing [TAB] and [SPACE] with the respective key presses for the characters)

Upvotes: 3

Views: 4665

Answers (3)

nelstrom
nelstrom

Reputation: 19562

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/.

Upvotes: 2

tonio
tonio

Reputation: 10541

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.

Upvotes: 7

codaddict
codaddict

Reputation: 455400

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

You can do

:%s/\t/  /g

Upvotes: 9

Related Questions