Working with code indentation in Vim?

I work on a team of 4-person engineers, mostly writing javascript, and sometimes doing ruby ​​and python. So, as a team, we use code all the time, and as most programmers do, each member of the team has their own favorite level of indentation and related settings. I am one of two team members who use and love Vim as the main code editor. I like my command, but I also like my indentation, which is used to use 4 space characters. For more context, here is what I use in my .vimrc:

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

Due to the large amount of code exchange and co-editing in a team, the main code files usually begin to appear as an array of mixed tables and spaces, so even the classic Vim trick for selecting all and pressing = for smart indentation does not have much effect.

Anyway, my question is this: in Vim (MacVim specifically) is there a better (more reliable) way to convert a code file from a dirty mixed indent to my preferred indent? Whether it's the .vimrc parameter or the command I entered when editing the file, I don't care.

Thanks for any suggestions in advance!

+4
source share
2 answers

Use :retab .

Having said that, I highly recommend that you, as a team, coordinate and use the indentation style when working together on a specific project.

+11
source

We have the same case of using javascript and ruby ​​in the same store.

 autocmd FileType * set tabstop=4|set shiftwidth=4 autocmd FileType ruby set tabstop=2|set shiftwidth=2 set expandtab 

I find that I like 4 spaces for javascript, but ruby ​​looks much better with two spaces.

I agree with Yaser, you need to set the standard (FTW spaces)

Once you decide to get rid of all the tabs, use grep to find the files: retab

 grep -P '\t' * -R -c 
+1
source

All Articles