views:

725

answers:

4

Hi everyone,

I use vim with various plugins for editing ruby code. I have proper syntax highlighting set up but I was wondering if anyone knew of a way to get ruby syntax checking, similar to what you might see in an IDE such as visual studio, radrails, etc?

Something that would simply turn stuff red or break highlighting when I'm missing an 'end' or have an improperly constructed line of code would be sweet.

I googled and came across this plugin, http://github.com/scrooloose/syntastic/tree/master but I was wondering if anyone had any better suggestions.

+1  A: 

The rails.vim plugin does excellent syntax highlighting, as long as you stay within some of its formatting confines. Couple this with auto-indentation (ggVG=) and you should be able to get a general sense of if the document is well formed, or not.

Kenny
Just for future reference, gg=G does the same and will save you a couple keystrokes.
Randy Morris
Word. I was aware of that stuff, but I was hoping that someone might know of something a little more ide-like.
roybotnik
Thanks for the tip rson, every keystroke counts :)
Kenny
A: 

Seems like a few people have tried this, but no one has tried too hard. Personally I recommend using autotest in a separate terminal window.

Try this, if you just want syntex errors.

If you want errors that happen at runtime as well, you might like this instead.

austinfromboston
A: 

Check out using the CTK plugin: http://www.vim.org/scripts/script.php?script_id=2618

and try this in your .vimrc:

" Compile Ruby code after writing (show warnings/errors)
function! Compile()
  " don't compile if it's an Rspec file (extra warnings)
  let name = expand('<afile>')
  if name !~ 'spec'
    CC
  endif
endfunction
autocmd BufWritePost *.rb call Compile()

That (with ctk.vim) will perform a compile every time when the file is saved.

thnetos
I should clarify, by "compile", I meant that it will run your ruby file with Ruby's syntax checking option (-w).
thnetos
+1  A: 

You can syntax check the current buffer in ruby without downloading any plugins. The command is ":w !ruby -c"