vim tab转换成space

在Vim中,有时需要将tab转换成space。

使用ret命令(replace tab)。

[range]ret[ab]! [new-tabstop]

举例:将第一行到文件尾的tab转换成space,每个tab用4个space替代。

:set expandtab
:%ret! 4

如果没有给定4,则用当前的tab宽度设定替换为space。

相关配置文件命令:

:set tabstop=4 设定tab宽度为4个字符

:set shiftwidth=4 设定自动缩进为4个字符

:set expandtab 用space替代tab的输入

:set noexpandtab 不用space替代tab的输入

WARNING: No any other purpose,keeping reminded! So sorry to offended,if necessary, contact me and I do change what I had done to protect your privileges!
原文地址:https://www.cnblogs.com/MimiSnowing/p/13436865.html