Vim自动缩进或保存时自动缩进

自动缩进

这非常方便,特别是如果正在使用Vim进行快速代码编辑,甚至进行长时间的编码会话。强制执行特定的缩进样式。

在~/.vimrc文件中,添加以下选项:

syntax enable
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab

新行将自动缩进,花括号将自动对齐。

保存时自动缩进

要在保存时自动缩进文件,请将此添加到您的vimrc中:

augroup autoindent
    au!
    autocmd BufWritePre * :normal migg=G`i
augroup End

如果只想对某些文件(例如sss文件)执行此操作,您可以更改正则表达式:

autocmd BufWritePre * :normal migg=G`i

autocmd BufWritePre *.scss :normal migg=G`i

操作方式

  • autocmd BufWritePre specifies this is a command to be executed automatically before writing the buffer to file.
  • '* matches the files to run this auto-command on. If we want only text files, use *.txt, or only html files, use *.html, etc.
  • :normal says to execute the following command in normal mode
  • mi pu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FullStack贾凯

喜欢不吝点桃心,土豪也可赏酒钱

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值