Linux VIM 格式化源码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wqfhenanxc/article/details/83825146

1. 格式化整个文件: gg=G

解析:

     gg - Goto the beginning of the file
     =   - apply indentation
     G   - till end of file

缩进默认的是4个空格,可以通过修改.vimrc改成2个空格。

2. 缩进行

以下为常用的缩进快捷操作和命令:

  • 当前行向右缩进一次:操作 >> 或者输入命令 :>
  • 当前行向左缩进一次:操作 << 或者输入命令 :<
  • 从第m行起,到第n行止向右缩进一次: 输入命令 :m,n> 
  • 从第m行起,到第n行止向左缩进一次: 输入命令 :m,n< 
  • 从第m行起共n行向右缩进一次: 输入命令 :m>n 
  • 从第m行起共n行向左缩进一次: 输入命令 :m<n

shift+v选中一行或多行后,也可以使用 > 和< 来缩进 。

猜你喜欢

转载自blog.csdn.net/wqfhenanxc/article/details/83825146