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:
Redefine tab as 4 spaces
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.
Unless you :set list
and have a custom value for listchars
, there's no difference, appearance-wise, between a tab and tabstop
spaces. Here you have the same buffer with and without :set list
:
<tab>foo
<space><space><space><space><space><space><space><space>bar
So… are you asking about "appearance" or functionality?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With