Automate rails.vim

ⅰ亾dé卋堺 提交于 2020-01-15 09:16:08

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/1014441/automate-rails-vim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!