在/usr/share/vim/vim70/filetype.vim(in MacOS X)中找到ruby类型的设置,为其增加不同的后缀,使得*.rb,*.rake等都识别为ruby代码进行语法高亮:
au BufNewFile,BufRead *.rb,*.rake,*.rbw,*.gemspec setf ruby
在.vimrc中设置以下内容,即可使得编辑*.rb和*.erb时tab缩进值为2,但是其他类型的文件仍然为4.
set expandtab ” To insert space characters whenever the tab key is pressed
set tabstop=4 ” To control the number of space characters that will be inserted when the tab key is pressed
set shiftwidth=4 ” To change the number of space characters inserted for indentation
set softtabstop=4 ” makes the spaces feel like real tabs
au BufRead,BufNewFile *.rb set expandtab
au BufRead,BufNewFile *.rb set tabstop=2
au BufRead,BufNewFile *.rb set shiftwidth=2
au BufRead,BufNewFile *.rb set softtabstop=2
au BufRead,BufNewFile *.erb set expandtab
au BufRead,BufNewFile *.erb set tabstop=2
au BufRead,BufNewFile *.erb set shiftwidth=2
au BufRead,BufNewFile *.erb set softtabstop=2