Vim Replace Tabs With Spaces
You can convert tabs to spaces in vim using the vim search and replace command.
Vim replace tabs with spaces. So first set the number of spaces a tab should be then set expandtab. After the expandtab option is set all the new tab characters entered will be changed to spaces. If you want to do this for selected text then first select the text in visual mode.
Sed i s t g. Specifically this vim tabs to spaces command is all you need. The above command will search entire file s for the tab t and replace with space globally g.
To convert each tab in the file to two spaces i used this command. If no trailing whitespace is found no change occurs and the e flag means no error is displayed. In a search s finds whitespace a space or a tab and finds one or more occurrences.
The following command deletes any trailing whitespace at the end of each line. Use expand tab to convert new tabs to spaces the expandtab property will ensure that when you hit tab it will actually use spaces. Set tabstop 2 shiftwidth 2 expandtab.
Command then all the tabs becomes spaces. For example to insert 4 spaces for a tab use. For multiple files use sed to replace tabs with spaces with tabs.
Do this globally g on each line meaning that if there is more than one tab on any line make sure you convert all of them. Open a file in vim and press f2 the tabs will be converted to 4 spaces and file will be saved automatically. 1 s t g note that in both of these examples the g character at the end of the command means global.