niyue

Editing Ruby File in Vim

In programming on December 27, 2007 at 10:34 AM

在/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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: