I have recently started using vim. I added :set tabstop=4
in my .vimrc to comply with the indentation scheme, but when I opened the file in another editor (gedit) it still uses 8 tab spaces. The formatting looks right inside vim. Any help how I can fix this?
Asked
Active
Viewed 148 times
0

Ingo Karkat
- 167,457
- 16
- 250
- 324

VJune
- 1,195
- 5
- 16
- 26
-
2You intend to use literal spaces instead of literal tabs? You are probably inserting tabs, which look correct in Vim, but will use whatever tab width is specified in the other editor. Use `set expandtab` to force the use of spaces instead of tab literals. – Michael Berkowski Oct 30 '13 at 19:43
-
thanks, how can force vim to make this change in current file? i.e. expand already present tabs – VJune Oct 30 '13 at 20:13
-
2Read over `:help retab` – Michael Berkowski Oct 30 '13 at 20:17
-
retab! works great, thanks for the link! – VJune Oct 30 '13 at 20:40
3 Answers
2
When setting tabstop it is also worth setting softtabstop and shiftwidth to the same value.
I set all the following at the same time (from my .vimrc file)
" tabstop: Width of tab character
" expandtab: When on uses space instead of tabs
" softtabstop: Fine tunes the amount of white space to be added
" shiftwidth Determines the amount of whitespace to add in normal mode
set tabstop =4
set softtabstop =4
set shiftwidth =4
set expandtab
Here is a great tutorial on how and why.
http://vimcasts.org/episodes/tabs-and-spaces/

Martin York
- 257,169
- 86
- 333
- 562
0
Make a similar change to the other editor. The width of the tab a property of the editor, not a property of the file.

pamphlet
- 2,054
- 1
- 17
- 27
-
Michael's comment about using spaces is a good one. This answer assumes OP wants to use tabs. – pamphlet Oct 30 '13 at 19:45
0
You need to "convert" tabs to blanks, the following code solves your problem.
:set expandtab

Acácio Veit Schneider
- 160
- 5
-
Thanks for answering. How can force vim to make this change in current file? i.e. expand already present tabs. – VJune Oct 30 '13 at 20:12
-