Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify that I want Vim to treat .ru files like .rb files

Tags:

vim

ruby

rack

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?

like image 555
Jimmy Lyke Avatar asked Feb 27 '11 04:02

Jimmy Lyke


3 Answers

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

au BufRead,BufNewFile *.ru setfiletype ruby
like image 93
Dylan Markow Avatar answered Nov 17 '22 23:11

Dylan Markow


Ensure the following lines are in your vimrc file:

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.

like image 28
paxdiablo Avatar answered Nov 17 '22 22:11

paxdiablo


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

like image 2
asymmetric Avatar answered Nov 17 '22 21:11

asymmetric