Back

使用VIM 进行文件的跳转

发布时间: 2011-03-28 12:05:00

今天看了会rails plugin  help, 很有收获,解决了我一直手工跳转到 partial的大问题。

安装了vim的童鞋请直接  :help rails-navigation

主要的意思就是:
在光标下,直接输入gf (不输入任何 !,  : 啥的。),就可以很智能的跳转。例如:
(星号代表 光标, 第一行代表 源代码,第二行代表会跳转到的目标文件)

Example uses of |gf|, and where they might lead.
(* indicates cursor position)
>
        Pos*t.first
<       app/models/post.rb ~
>
        has_many :c*omments
<       app/models/comment.rb ~
>
        link_to 'Home', :controller => 'bl*og'
<       app/controllers/blog_controller.rb ~
>
        <%= render 'sh*ared/sidebar' %>
<       app/views/shared/_sidebar.html.erb ~
>
        <%= stylesheet_link_tag 'scaf*fold' %>
<       public/stylesheets/scaffold.css ~
        class BlogController < Applica*tionController
<       app/controllers/application_controller.rb ~
>
        class ApplicationController < ActionCont*roller::Base
<       .../action_controller/base.rb ~
>
        fixtures :pos*ts
<       test/fixtures/posts.yml ~
>
        layout :pri*nt
<       app/views/layouts/print.html.erb ~
>
        <%= link_to "New", new_comme*nt_path %>
<       app/controllers/comments_controller.rb (jumps to def new) ~



1. 跳转到对应的文件: (我用了  cmd-T 的plugin)
2. 只要进入任意一个 model/controller/view,就可以通过  :Rview, :Rcontroller, :Rmodel 命令任意跳转,我通过下面的 vimrc文件进行了快捷键的设置:  (改快捷键需要在你的环境下调试。因为在windows下的SSH客户端(putty), alt无法正常工作)

map <C-S-M> :Rmodel<CR>
map <C-S-C> :Rcontroller<CR>
map <C-S-U> :Runit<CR>
map <C-S-L> :Rfunctional<CR>
map <C-V> :Rview<CR>


Back