Set Vim Filetype or Syntax with Modeline
Here's a problem I faced today: I'm writing a Thor CLI. The convention for that project is a file called cli
, written in Ruby but with no .rb
extension. Vim highlights it and otherwise treats it like a conf file, but it's Ruby. I want my editor to progamatically recognize that and act accordingly.
One solution is Vim's modeline. With modeline enabled, either of these settings will enable syntax highlighting on buffer read. They can both be used at the same time as shown.
# vi: syntax=ruby
# vi: filetype=ruby
def ruby_here
end
Tweet