dan-klasson
dan-klasson

Reputation: 14180

Easy way to set indentation on whole file

I screwed up the formatting on a few files using VIM. What I thought was tabs was something that looked like tabs. Is there an easy to change the formatting back to standard tabs?

I can find a lot of info on doing from tabs to spaces, but not the other way around.

Upvotes: 0

Views: 1242

Answers (1)

qiubix
qiubix

Reputation: 1332

You can do this by disabling expanding tabs to spaces, and than replacing every sequence of whitespace with tabs:

:set expandtab 
:%retab!

Note: Retab command takes range, so you can execute it on the part of the file. Also, before executing this command, set proper size of tab, depending on your preferences, for example:

:set tabstop=2

This means that every two spaces will be replaced by tab.

Upvotes: 3

Related Questions