Posted by virantha on Mon 12 May 2014

Changing tab stops in Vim

I normally use spaces in my files instead of tabs for indentation, with 4 being my default indent width. Sometimes, I need to change this on existing files to 2, so for the most part, the following sequence works. First,

set ts=4 sts=4 noet
retab!

This changes every 4-space to a tab, then retabs (exclamation point is important).

Then, change the tabs into spaces:

set ts=2 sts=2 et
retab!

You can also setup your vimrc to have certain files like HTML use a different tabstop than your regular files:

autocmd FileType html :setlocal sw=2 ts=2 sts=2

© Virantha Ekanayake. Built using Pelican. Modified svbhack theme, based on theme by Carey Metcalfe