Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace tabs with spaces in vim

Tags:

vim

vi

I would like to convert tab to spaces in gVim. I added the following line to my _vimrc:

set tabstop=2 

It works to stop at two spaces but it still looks like one tab key is inserted (I tried to use the h key to count spaces afterwards).

I'm not sure what should I do to make gVim convert tabs to spaces?

like image 343
David.Chu.ca Avatar asked Jan 09 '09 03:01

David.Chu.ca


People also ask

How do you convert all tabs to spaces in vim?

vim Whitespace Convert tabs to spaces and spaces to tabs If you enable expandtab again :set expandtab then and run the :retab! command then all the tabs becomes spaces.

How do I replace a tab with 4 spaces in vim?

replace space by tab in vim you can do this: # first in . vimrc set up :set expandtab :set tabstop=4 # or you can do this :set tabstop=4 shiftwidth=4 expandtab # then in the py file in command mode, run :retab!

What is Expandtab in Vim?

Use expand tab to convert new tabs to spaces The expandtab property will ensure that when you hit tab it will actually use spaces. So first set the number of spaces a tab should be, then set expandtab. set tabstop=2 shiftwidth=2 expandtab. Tabstop determines how many columns a tab counts for.


1 Answers

Once you've got expandtab on as per the other answers, the extremely convenient way to convert existing files according to your new settings is:

:retab 

It will work on the current buffer.

like image 147
ʞɔıu Avatar answered Oct 12 '22 22:10

ʞɔıu