Opciones de sangría de Vim
Vim utiliza principalmente 3 configuraciones en cuanto al tamaño de sangría:
tabstop, ts: cuando Vim encuentra una tabulación en un archivo que está abriendo, muestra la pestaña como {ts} espacios (consulte la ayuda de tabulación , o escriba :help tabstopVim).
softtabstop, sts: cuando está editando un archivo y presiona la tecla de tabulación, Vim utiliza esta configuración para definir el ancho de la tabulación insertada (consulte la ayuda de softtabstop o escriba :help softtabstopVim).
shiftwidth, sw: El número de espacios Vim utiliza cuando la sangría, ya sea usando cosas autoindent o la costumbre >>, <<los comandos. Como Heptite notó, esto es lo que estaba buscando en este caso particular. Y las versiones recientes de Vim de hecho le permiten no definir esta opción, shiftwidthluego tomarían el valor definido por tabstop. Muy útil (consulte la ayuda de Shiftwidth ).
Ejemplo
Entonces, por ejemplo, si usa la siguiente configuración:
set sts=4
set ts=2
set sw=8
Estos producirían el siguiente comportamiento:
- Insertar una tabulación en el archivo produciría una sangría de 4 espacios de ancho.
- Como su
tabstopse establece en 2, esto sería en realidad el equivalente de 2 tabulaciones. Esto es bastante fácil de verificar, solo use las opciones listy listcharspara mostrar las tabulaciones.
- Si sangra una línea usando
>>, la sangría sería de 8 espacios de ancho (por lo tanto, el equivalente a 4 tabulaciones, en función del tabstopvalor, igual que el anterior).

Recomendaciones de sangría de Vim (de la documentación de Vim)
De tabstopayuda ( :help tabstopen Vim):
There are four main ways to use tabs in Vim:
1. Always keep 'tabstop' at 8, set 'softtabstop' and 'shiftwidth' to 4
(or 3 or whatever you prefer) and use 'noexpandtab'. Then Vim
will use a mix of tabs and spaces, but typing <Tab> and <BS> will
behave like a tab appears every 4 (or 3) characters.
2. Set 'tabstop' and 'shiftwidth' to whatever you prefer and use
'expandtab'. This way you will always insert spaces. The
formatting will never be messed up when 'tabstop' is changed.
3. Set 'tabstop' and 'shiftwidth' to whatever you prefer and use a
|modeline| to set these values when editing the file again. Only
works when using Vim to edit the file.
4. Always set 'tabstop' and 'shiftwidth' to the same value, and
'noexpandtab'. This should then work (for initial indents only)
for any tabstop setting that people use. It might be nice to have
tabs after the first non-blank inserted as spaces if you do this
though. Otherwise aligned comments will be wrong when 'tabstop' is
changed.
Yo personalmente uso principalmente la segunda solución, con tabulaciones de 2 espacios de ancho.
set ts=2
set sts=2
set et "expand tabs to spaces
tscomo 2, 4 u 8