mperezi
5/21/2019 - 10:11 AM

Retab files using VIM

How to re-indent a file from 4 spaces to tabs and a width of 2: http://ppanyukov.github.io/2011/06/29/retabbing-in-vim.html

# Step 0. (Optional) Tell VIM to show whitespace:
:set list

# Step 1. Tell VIM what the the current tabsize is:
:set tabstop=4      # Tab size is 4 spaces

# Step 2. Convert spaces to real tabs:
:set noexpandtab    # Use real tab instead of space
:retab!             # Replace all space-tabs with real tabs

# Step 3. Convert real tabs back to spaces, using tabsize 2
:set expandtab      # User spaces instead ot tab
:set tabstop=2      # 2 spaces for each tab
:retab              # Reformat using new tabbing policy

# All in one line
:set ts=4 noet | retab! | set et ts=2 | retab