如何指定我希望Vim处理.ru文件之类的.ru文件

时间:2023-01-13 10:08:22

Whenever I use Vim with Ruby files, I get nice coloring and automatic indention on blocks. However, when I am editing a Rack file, I don't get these things. How can I extend my Vim/Ruby configuration with my Rack files?

每当我使用Vim和Ruby文件时,我都会在块上获得漂亮的颜色和自动缩进。但是,当我编辑Rack文件时,我没有得到这些东西。如何使用Rack文件扩展我的Vim / Ruby配置?

3 个解决方案

#1


15  

Put this in your vimrc to tell vim to associate *.ru files with ruby syntax highlighting.

把它放在你的vimrc中告诉vim将* .ru文件与ruby语法高亮关联起来。

au BufRead,BufNewFile *.ru setfiletype ruby

#2


6  

Ensure the following lines are in your vimrc file:

确保vimrc文件中包含以下行:

syntax on
filetype on
au BufNewFile,BufRead *.ru set filetype=ruby

The first two are probably already set if other files are syntax-colored, but I've put them there anyway.

如果其他文件都是语法颜色的话,前两个可能已经设置了,但无论如何我都把它们放在那里。

The final one sets automatic actions on creating a new file and opening an existing file, to set the file type based on the extension.

最后一个设置自动操作以创建新文件和打开现有文件,以根据扩展名设置文件类型。

#3


2  

You can install the vim-ruby plugin by tpope, which will do this and much more!

您可以通过tpope安装vim-ruby插件,这将执行此操作以及更多内容!

#1


15  

Put this in your vimrc to tell vim to associate *.ru files with ruby syntax highlighting.

把它放在你的vimrc中告诉vim将* .ru文件与ruby语法高亮关联起来。

au BufRead,BufNewFile *.ru setfiletype ruby

#2


6  

Ensure the following lines are in your vimrc file:

确保vimrc文件中包含以下行:

syntax on
filetype on
au BufNewFile,BufRead *.ru set filetype=ruby

The first two are probably already set if other files are syntax-colored, but I've put them there anyway.

如果其他文件都是语法颜色的话,前两个可能已经设置了,但无论如何我都把它们放在那里。

The final one sets automatic actions on creating a new file and opening an existing file, to set the file type based on the extension.

最后一个设置自动操作以创建新文件和打开现有文件,以根据扩展名设置文件类型。

#3


2  

You can install the vim-ruby plugin by tpope, which will do this and much more!

您可以通过tpope安装vim-ruby插件,这将执行此操作以及更多内容!