开发者

Easily create a Ruby on Rails partial from an existing block of markup using vim

开发者 https://www.devze.com 2023-01-07 23:12 出处:网络
Is there currently a plugin that you ruby on rails developers that are also using macvim/gvim/vi开发者_C百科m that allows you to take a quick block of code and create a partial from it? I know that Te

Is there currently a plugin that you ruby on rails developers that are also using macvim/gvim/vi开发者_C百科m that allows you to take a quick block of code and create a partial from it? I know that TextMate does this, figured someone has ported it by now to vim also.


You want Tim Pope's rails.vim plugin:

http://rails.vim.tpope.net/

It provides an :Rextract command that pulls a range of lines into a partial. Here's a very short demo of it in action:

http://rails.vim.tpope.net/images/rpartial.gif

(The :Rpartial command in the demo is an alias for :Rextract.)

The plugin provides dozens of other features, too, and many people consider it a must-have for Rails development in Vim.


It works in vim with vim-rails plugin.

  1. Select in visual mode code which you need to send to partial
  2. Press key : and you will see :'<,'>
  3. Complete command to :'<,'>Rextract partial_name where partial_name will your partial's file name. You can set folder for partial, for example :'<,'>Rextract shared/menu
  4. Press Enter and enjoy.


rails.vim can do this. From the features summary:

:Rextract file replaces the desired range (ideally selected in visual line mode) with render :partial => 'file', which is automatically created with your content. The @file instance variable is replaced with the file local variable.

0

精彩评论

暂无评论...
验证码 换一张
取 消