Sam Kong
Sam Kong

Reputation: 5810

Automate rails.vim

I use vim(in console) 7.1 for rails developments on OSX or Ubuntu. Here's what I repeatedly do when I edit files of rails.

cd RAILS_ROOT vim

:Rproject .project

Is there a way that the last part is automatically done? For example, I just type 'vim -some_arg' and it automatically triggers ":Rproject .project"? If that's not possible, can I alias "Rproject .project" to "Rp"?

I am familiar with vim editing but not vim script. Help me please.

Sam

Upvotes: 1

Views: 607

Answers (1)

Ben Hughes
Ben Hughes

Reputation: 14185

there is probably a better way to do this, but I don't feel like messing with load order or the like.

You can edit rails.vim and add one line. It works as I would expect in my tests.

" Initialization {{{1

augroup railsPluginDetect
  autocmd!
  autocmd BufNewFile,BufRead * call s:Detect(expand("<afile>:p"))
  autocmd VimEnter * if expand("<amatch>") == "" && !exists("b:rails_root") | call s:Detect(getcwd()) | endif | if exists("b:rails_root") | silent doau User BufEnterRails | endif
  autocmd FileType netrw if !exists("b:rails_root") | call s:Detect(expand("<afile>:p")) | endif | if exists("b:rails_root") | silent doau User BufEnterRails | endif
  autocmd BufEnter * if exists("b:rails_root")|silent doau User BufEnterRails|endif
  autocmd BufLeave * if exists("b:rails_root")|silent doau User BufLeaveRails|endif
  autocmd Syntax railslog if s:autoload()|call rails#log_syntax()|endif

  " Add this line here
  autocmd VimEnter * if expand("<amatch>") == "" && !exists("b:rails_root") | call s:Detect(getcwd()) | endif | if exists("b:rails_root") | Rproject .project | endif
  " ^ this one

augroup END

Upvotes: 3

Related Questions