在Vim中进行空格和TAB

  • TAB替换为空格
:set ts=4
:set expandtab
:%retab!
  • 空格替换为TAB:

    set ts=4
    set noexpandtab
    %retab!
    
    • 加!是用于处理非空白字符之后的TAB,即所有的TAB,若不加!,则只处理行首的TAB
  • 使用命令行进行批量转换:

      for f in $(find -name "*.py");do vim -c 'set ts=4|%retab!|wq' $f;done
    
  • Ref:

Search

    Table of Contents