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

最低0.47元/天 解锁文章
962

被折叠的 条评论
为什么被折叠?



