How to make existing tabs display as 4 spaces in vim?

I'm working on a git repository that has all of its indentation as tabs, but I like to work in spaces (4 spaces per indent). I don't want to just do text replacement on the tabs because then I would have a terrible mess of my differences. Instead, I want vim to display the tabs as if they were spaces.

I created this question after reading this:

Redefine tab as 4 spaces

One of 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

      

It looks like launching :set expandtab

will cause the tabs to appear as spaces. Apparently this is not the case. How can I achieve what I need? I am using vim 7.4

.

+3


source to share


4 answers


From command mode, just call

:retab

      

This will convert existing tabs to spaces (if you have the :set expandtab

ones you already have in .vimrc

). Also, since you already set the tabstop

value to 4

spaces, :retab

will use that value and replace existing tabs with 4

spaces.

Check the online help for more information



:help retab

      

And if you want to do more nifty things check out this link: http://vim.wikia.com/wiki/Super_retab

inclusion expandtab

does not convert existing tabs to spaces, only new insertion of TAB characters is expanded.

+1


source


If you don't :set list

and have a custom value for listchars

, tabstop

there is no difference between the tab and the outer elements. Here you have the same buffer with and without :set list

:

<tab>foo
<space><space><space><space><space><space><space><space>bar

      



tabs vs spaces

So ... are you asking about "looks" or functionality?

+1


source


These are the settings I'm using:

set tabstop=4
set shiftwidth=4
set noexpandtab

      

0


source


gg=G

      

Your settings are correct. You just need to rearrange the document.

0


source







All Articles