How can I get Syntastic to recognize newer Ruby syntax?
I'm using Syntastic in Vim, and it highlights newer Ruby syntax as errors. For example, if I use required keyword arguments (introduced in Ruby 2.1), like this:
def distance(from:, to:)
# whatever
end
... it highlights the definition line and says "unexpected ','".
How can I get it to recognize this as valid Ruby syntax? I've already updated ~/.vim/syntax/ruby.vim
.
Solution 1:
Specify the ruby executable for Syntastic
Syntastic calls ruby -c
to check the syntax of a file, so the errors it shows depends on which version of ruby its using.
You can point it to the one you want to use like this:
let g:syntastic_ruby_exec = 'path/to/ruby/executable'
NOTE: on newer versions of Syntastic:
let g:syntastic_ruby_mri_exec = 'path/to/ruby/executable'
$ type ruby
will tell you where your current Ruby executable is. Ruby installers have their own conventions about where they place their binaries. Eg:
-
ruby-install puts ruby installations in
~/.rubies
and specific versions at paths like~/.rubies/ruby-2.2.0/bin/ruby
-
RVM puts ruby installations in
~/.rvm/rubies
and specific versions at paths like~/.rvm/rubies/ruby-2.2.0/bin/ruby
Solution 2:
Using terminal macvim I also had this problem, which was compounded by the fact that I was using zsh, which for some reason was not respecting the rvm binary I gave syntastic. I realized that my paths where incorrect when running !echo $PATH
in terminal macvim, I had several system paths appended to the top that were not in my regular shell still causing the default MRI to load.
To fix this, I did not need to specify the syntax checker at all in my .vimrc, however I had to update how zsh started. Using the thread at: http://vim.1045645.n5.nabble.com/MacVim-and-PATH-td3388705.html I ended up simply running sudo mv /etc/zshenv /etc/zprofile
and now everything works and my paths are correct in mvim. This should also solve the problem of updating syntastic when installing a new ruby version via rvm.