views:

271

answers:

1
+1  Q: 

Automate rails.vim

Hi,

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

+3  A: 

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
Ben Hughes
Thank you. It works great!
Sam Kong