rails.vim and those pesky “E345: Can’t find file “xxx” in path” errors

by gabebw

So, I’ve been loving rails.vim over the past few weeks. I haven’t even touched TextMate.

hypnotoad

ALL HAIL VIM

But there’s one thing that’s been bothering me. I kept getting these weird errors, like this: “E345: Can't find file "spec/controllers/sessions_controller_spec.rb" in path” and I then I had to restart vim to have :Rspec controllers/sessions work again. And then at a random point, it would start giving me E345‘s again. It’s a testament to how awesome rails.vim is that these apparently random failures still didn’t deter me (or maybe I’m just kind of dumb).

Today, thanks to this Github issue, I finally found the answer: The :mkview’s in my vimrc. I had this:

autocmd BufWinLeave ?* mkview
autocmd BufWinEnter ?* silent loadview

And when I commented them out, everything worked great. Of course, now I didn’t have any views – how could I get Vim to save my last cursor position without views? Thanks to this vimrc, I found the magic snippet:

autocmd BufReadPost *
    \ if line("'\"") > 0 && line("'\"") <= line("$") |
    \ exe "normal g`\"" |
    \ endif

And voila! rails.vim works, and I have my cursor position saved!

Advertisements