If you want to convert tabs into spaces in a document opened by VIM, use the following steps:

set parameter permanently

To use your settings for every (new) VIM session enter the following parameters in your ~/.vimrc file:

(For the examples we assume your tab width to be 2, but you can replace it with any width you like, e.g. 8.)

  • set the tab width to 2 columns:

    set tabstop=2
    
  • set the shift width (for intendations) to 2 spaces:

    set shiftwidth=2
    
  • use spaces instead of tabs:

    set expandtab
    

set partameter temporarily

To set these parameters only for the current edition session use this command in “command mode”. (The colon “:” enters the command mode):

:set tabstop=2 shiftwidth=2 expandtab

apply settings to existing tabs

To apply your tab width and “space instead of tabs” setting to already existing tabs in the open document or a marked area, enter the command:

:retab