Get a site

Replace spaces with tabs using Vim

It often happens that you are modifying a text file and you want to replace spaces with tabs using Vim text editor. There is nothing easier!

Replace spaces with tabs using Vim
Vim logo

Firstly, set the proper flag to use tabs instead of spaces:

:set noexpandtab    " Use tabs, not spaces

Then retabulate the whole file:

:%retab!            " Retabulate the whole file

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Published by Francesco Serafin

I am a PhD student at the Department of Civil, Environmental and Mechanical Engineering at the University of Trento. My two greatest loves: Computer Science and Water (take three with my Lenovo!:D). As a result, the aim of my life is to make both passions coexist. My gpg public key available at

Leave a Reply

Your email address will not be published.

%d bloggers like this: