I am working in a git repository that has all of its indenting as tabs, but I like to work in spaces (4 spaces per indent). I don't want to just do a text replace of the tabs because then I'll end up having a horrible mess in my diffs. Instead, I want vim to make tabs appear as if they're spaces.
I created this question after reading this one:
One the answers (from Alan Haggai Alavi) says the following:
set tabstop=4 " The width of a TAB is set to 4.
" Still it is a \t. It is just that
" Vim will interpret it to be having
" a width of 4.
set shiftwidth=4 " Indents will have a width of 4
set softtabstop=4 " Sets the number of columns for a TAB
set expandtab " Expand TABs to spaces
This seems to suggest that running :set expandtab
will make tabs appear as spaces. Apparently that's not the case. How can I achieve what I'm after? I'm using vim 7.4
.
From command mode, just invoke
:retab
This will convert existing tabs to spaces (given you have :set expandtab
, which you already have in your .vimrc
). Plus, since you already have set tabstop
value to 4
spaces, :retab
will use that value and replace existing tabs to 4
spaces.
For more information check the inbuilt help
:help retab
And if you want do more nifty things, check out this link : http://vim.wikia.com/wiki/Super_retab
enabling expandtab
does not convert existing tabs to spaces, only new insertion of TAB characters are expanded.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments