Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Modeline not being set for ruby/eruby files #128

raklet opened this Issue Jan 30, 2013 · 5 comments


None yet
3 participants

raklet commented Jan 30, 2013

When I create a random single .rb or .erb file, the filetype is recognized as ruby/eruby (which is set from ~/.vim/bundle/vim-ruby/ftdetect/ruby.vim), syntax, colors, highlighting, omnicompletion all function, but the modeline is not being set.

The following commands return these values:

:verbose set modeline? #last set from ~/.vimrc
:verbose set modelines? #returns modelines=5
:verbose set sw sts ts expandtab? #shiftwidth=8 softtabstop=0 tabstop=8 noexpandtab

I also have the vim-rails bundle installed in ~/.vim/bundle. The modeline works correctly for .rb and .erb files that are part of a rails project. Filetypes are determined and set by vim-ruby/ftdetect/ruby.vim, but

:verbose set sw sts ts expandtab? #shiftwidth=2 softtabstop=2 tabstop=8 expandtab

With all of these values being set from vim-rails/autoload/rails.vim

Any idea why the ruby.vim modeline is not being applied?


tpope commented Jan 30, 2013

Your use of the word "modeline" here suggests you might not understand what one is. "The modeline is not being set" doesn't really make any sense. Can you clarify what you mean by modeline and what you expect to happen?

raklet commented Jan 30, 2013

Yes, you are right. I am a total VIM virgin. I started using it a couple days ago with no prior experience. I spent hours looking for answers before asking for help, and the best I could muddle out was that a modeline is a commented line that occurs in the top or bottom (generally 5 lines) of a .vim file. This line provides instructions to vim on how to set tabstop, shiftwidth, softtabstop, etc. At least that was my understanding.

I see the following line in the bottom of autoload/rails.vim
" vim:set sw=2 sts=2:
and that appears to provide the proper 2 space indent behavior for files in a rails project.

I see similar lines at the bottom of ftdetect/ruby.vim, indent/ruby.vim, etc. I assumed that one of those lines would setup the 2 space indent for ruby files that are not part of a rails project.

It is highly likely that my assumption is wrong and that plain ruby files have some other default indent spacing, but I haven't found anywhere that states what that is, nor can I figure it out from looking at the scripts. I'm trying my best to RTFM and figure things out on my own, but so far, I'm just floundering in the dark. Any enlightenment would be greatly appreciated.


AndrewRadev commented Jan 30, 2013

It's true that the modeline provides instructions to Vim, but they're only effective for the current file that you're looking at. For example, if you have a ruby file like this:

def foo

# vim: sw=4 sts=4

Then this last line is an instruction to Vim to override any "normal" settings and use 4 spaces of indent for just this file. You've seen these in ftdetect/ruby.vim and indent/ruby.vim, but they are instructions for those vimscript files, not for ruby files.

In order to get 2 spaces of indenting for ruby files, you should create a file named ~/.vim/ftplugin/ruby.vim and place the following in it:

setlocal expandtab
setlocal shiftwidth=2
setlocal softtabstop=2

You could probably also do it with autocommands, but this is the recommended way, so I'll skip that explanation. For more information, a good place to start from is :help filetype-plugin (simply execute this in command-line mode). You could also find this information online.

These settings are not used by default since it's something of a Vim policy to consider these "user" settings that you need to decide on and set yourself. For a more detailed discussion, see issue #48.

raklet commented Jan 30, 2013

Thanks! That was very clear. Can you suggest a more appropriate place for when I have questions? I'm sure "Issues" doesn't mean my issues.

@raklet raklet closed this Jan 30, 2013


AndrewRadev commented Jan 30, 2013

A few channels to get help can be found on vim.org's "community" page. I think in your case, the Vim user support mailing list and the IRC channel could be a good fit -- from the description, they seem newbie-friendly. Admittedly, I haven't used either of them, so I can't really say if that's the case, but it looks like a safe bet to start from.

Other than that, Stack Overflow and reddit have Vim-specific areas. SO in particular is a good place to get concrete questions answered -- repliers tend to be friendly and often quite verbose in explanations. And reddit's /r/vim spawns a lot of interesting discussions on workflows, plugins, various tips and tricks. I would suggest you visit these two sites on a regular basis if only to skim through the topics, even if you don't understand them at first.

Good luck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment