vi/vim editor FAQ: How do I convert tabs to spaces in vim?
You can convert tabs to spaces in vim using the vim search and replace command. Specifically, this vim “tabs to spaces” command is all you need:
In short, this command can be read like this:
- From the first line to the last line (
- Swap each tab (
\t) with two spaces (i.e., convert each tab to two spaces)
- 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.
Regarding that last line, if for some reason you just want to convert the first tab on each line to spaces, use the same command, but omit the
g at the end, like this:
In summary, that command is all you need to convert tabs to spaces in the vim editor
help support my writing