有人能够简单地向我解释根据文件类型更改Vim缩进行为的最简单方法吗? 例如,若是我打开Python文件,则应缩进2个空格,可是若是我打开Powershell脚本,则应缩进4个空格。 html
就我的而言,我在.vimrc中使用如下设置: java
autocmd FileType python set tabstop=8|set shiftwidth=2|set expandtab autocmd FileType ruby set tabstop=8|set shiftwidth=2|set expandtab
将基于文件后缀的autocmd命令放在〜/ .vimrc中 python
autocmd BufRead,BufNewFile *.c,*.h,*.java set noic cin noexpandtab autocmd BufRead,BufNewFile *.pl syntax on
您正在寻找的命令多是ts =和sw = shell
我一般使用expandtab
设置,但这对makefile不利。 我最近补充说: vim
:autocmd FileType make set noexpandtab
到个人.vimrc文件的末尾,它会将Makefile,makefile和* .mk识别为makefile,而且不会展开选项卡。 大概能够扩展它。 ruby
使用ftplugins或自动命令来设置选项。 学习
在~/.vim/ftplugin/python.vim:
spa
setlocal shiftwidth=2 softtabstop=2 expandtab
而且不要忘记在~/.vimrc
打开它们: .net
filetype plugin indent on
( :h ftplugin
了解更多信息) 插件
在~/.vimrc
:
autocmd FileType python setlocal shiftwidth=2 softtabstop=2 expandtab
您能够将任何长命令或设置替换为其短版本:
autocmd
: au
setlocal
: setl
shiftwidth
: sw
tabstop
: ts
softtabstop
: sts
expandtab
: et
我还建议学习tabstop
和softtabstop
之间的区别。 不少人不了解softtabstop
。
您能够添加.vim
文件,只要vim切换到特定文件类型便可执行。
例如,我有一个~/.vim/after/ftplugin/html.vim
,内容以下:
setlocal shiftwidth=2 setlocal tabstop=2
这致使vim使用宽度为2个字符的制表符进行缩进( noexpandtab
选项在个人配置中的其余位置全局设置)。
对此进行了描述: http : //vimdoc.sourceforge.net/htmldoc/usr_05.html#05.4 ,向下滚动至文件类型插件部分。