Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dealing with code indentation in Vim?

I work on an engineering team of 4 people, mostly writing javascript while occasionally dabbling in ruby and python. So, as a team, we share code all the time, and as most programmers do, each member of the team has his favorite level of indentation & related settings. I am one of 2 members of the team who use and love Vim as my primary code editor. I love my team but I also love my indentation, which happens to use 4-space tab characters. For more context, here's what I use in my .vimrc:

set ts = 4 sts = 4 sw = 4 expandtab " 4 space tabs

With so much code-sharing and collaborative editing going on in the team, the main code files usually start to appear as a mass of mixed tab & space mayhem, so that even the classic Vim trick of selecting all and pressing = to smart indent doesn't have much effect.

Anyway, my question is this: In Vim (MacVim specifically) is there a better (more reliable) way of converting a code file from messy, mixed indentation to my preferred indentation? Whether it be a .vimrc setting or a command I enter while editing the file, I don't care.

Thanks for any suggestions in advance!

like image 571
Alex Avatar asked Dec 16 '22 21:12

Alex


1 Answers

Use :retab.

Having said that, I strongly suggest that you, as a team, agree on and use an indentation style when working collaboratively on a certain project.

like image 180
Yaser Sulaiman Avatar answered Jan 12 '23 22:01

Yaser Sulaiman