How do I make existing tabs appear as 4 spaces in vim?

quant

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.

xk0der

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I make vim's autoindent not drop trailing spaces?

From Dev

How do I get vim to show trailing whitespace, but use blank spaces for tabs?

From Java

How can I convert tabs to spaces and vice versa in an existing file

From Dev

How to highlight tabs and spaces in vim

From Dev

How to insert Tabs(not spaces) in vim?

From Dev

How do I make Kate indent with spaces on Python files but use tabs for text files and other files?

From Dev

How do I make Kate indent with spaces on Python files but use tabs for text files and other files?

From Dev

How do I make commit diff appear in commit message while I'm editing it (with Vim)?

From Dev

How can I make a terminal with 3 tabs appear after startup?

From Dev

How can I make a terminal with 3 tabs appear after startup?

From Dev

How do I make a chart appear in SSRS?

From Java

How do I configure Notepad++ to use spaces instead of tabs?

From Java

How do I change Eclipse to use spaces instead of tabs?

From Dev

How to make spaces wider in vim?

From Dev

How do I open separate tabs/windows for all buffers in Vim?

From Dev

Vim tabs and spaces

From Dev

Vim: changing tabs to spaces

From Dev

In Vim, how can I automatically determine whether to use spaces or tabs for indentation?

From Dev

How to make Emacs use tabs instead of spaces?

From Dev

How do I make Vim respect .editorconfig?

From Dev

how do I make a replacement with ampersand "&" in vim?

From Dev

How do I indent entire file by n spaces in VIM?

From Dev

How do I search words separated by spaces in Vim

From Dev

How do I search words separated by spaces in Vim

From Dev

How do I edit an existing buffer in a new tab in vim?

From Dev

How do I make dynamic shiny tabs with their own content?

From Dev

How can I make difftool Meld insert spaces instead of tabs on editing?

From Dev

How do I make main content appear in front of background in middle?

From Dev

How do I make images appear and disappear without an event or buttons

Related Related

  1. 1

    How do I make vim's autoindent not drop trailing spaces?

  2. 2

    How do I get vim to show trailing whitespace, but use blank spaces for tabs?

  3. 3

    How can I convert tabs to spaces and vice versa in an existing file

  4. 4

    How to highlight tabs and spaces in vim

  5. 5

    How to insert Tabs(not spaces) in vim?

  6. 6

    How do I make Kate indent with spaces on Python files but use tabs for text files and other files?

  7. 7

    How do I make Kate indent with spaces on Python files but use tabs for text files and other files?

  8. 8

    How do I make commit diff appear in commit message while I'm editing it (with Vim)?

  9. 9

    How can I make a terminal with 3 tabs appear after startup?

  10. 10

    How can I make a terminal with 3 tabs appear after startup?

  11. 11

    How do I make a chart appear in SSRS?

  12. 12

    How do I configure Notepad++ to use spaces instead of tabs?

  13. 13

    How do I change Eclipse to use spaces instead of tabs?

  14. 14

    How to make spaces wider in vim?

  15. 15

    How do I open separate tabs/windows for all buffers in Vim?

  16. 16

    Vim tabs and spaces

  17. 17

    Vim: changing tabs to spaces

  18. 18

    In Vim, how can I automatically determine whether to use spaces or tabs for indentation?

  19. 19

    How to make Emacs use tabs instead of spaces?

  20. 20

    How do I make Vim respect .editorconfig?

  21. 21

    how do I make a replacement with ampersand "&" in vim?

  22. 22

    How do I indent entire file by n spaces in VIM?

  23. 23

    How do I search words separated by spaces in Vim

  24. 24

    How do I search words separated by spaces in Vim

  25. 25

    How do I edit an existing buffer in a new tab in vim?

  26. 26

    How do I make dynamic shiny tabs with their own content?

  27. 27

    How can I make difftool Meld insert spaces instead of tabs on editing?

  28. 28

    How do I make main content appear in front of background in middle?

  29. 29

    How do I make images appear and disappear without an event or buttons

HotTag

Archive