Software dev, tech, mind hacks and the occasional personal bit

Vim with find file for Rails (like TextMate)

In a fit of TextMate jealousy, several months ago, I scoured the web for a way to get find-file functionality info my favourite Ruby/Rails editor, vim. I was very happy to find that Jamis Buck had developed an aweseome plugin do to this. It is a little fiddly to install, but worth the trouble. Here’s some simplified steps to get you going.

  • Install Jamis’s ruby gem
    sudo gem install jamis-fuzzy_file_finder --source=http://gems.github.com
  • Download this fuzzyfinder script and pop it in your ‘~/.vim/plugin’ directory. Note that the most recent versions of this script are incompatible with Jamis’s plugin.
  • Grab the latest version of ‘fuzzyfinder_textmate.vim’ from http://github.com/jamis/fuzzyfinder_textmate/tree/master and pop it in your ‘~/.vim/plugin’ directory

Then, if you want to have a similar sort of light-weight Rails ‘IDE’ I enjoy coding with, see my config files below:

.vimrc

source $VIMRUNTIME/vimrc_example.vim
behave xterm
set nu
set tabstop=2
set shiftwidth=2
set softtabstop=2
set ai
set expandtab
set smarttab
let g:rubycomplete_rails = 1

map f :FuzzyFinderTextMate<CR>
map n :tabnew<CR>
map c :tabclose<CR>
map m :tabnext<CR>

let g:fuzzy_ignore = "*.svn"
let g:fuzzy_ignore = "*.swp"
let g:fuzzy_ignore = "*.jpg"
let g:fuzzy_ignore = "*.gif"
let g:fuzzy_ignore = "*~"

set nobackup

.gvimrc

source ~/.vimrc
set selectmode=mouse
set columns=100
set lines=50

In this set up, there are no chords etc. Instead, when not in edit mode, ‘n’ will open a new tab. ‘f’ will let you find a new file to open in the current tab. ‘c’ will close the current tab and ‘m’ will move between tabs. So in a normal workflow, you might decide to swap the file in the current tab for a new one (simply press ‘f’), or if you need another file open, hit ‘n’ for new tab, and then ‘f’ to load the relevant file. My text description doesn’t do it justice, but I find this works very well to get you to the file you want quickly, and let you have the files you’re interested in open all at the same time.

One last note, remember to start vim/gVim in the root of your rails directory.

Happy Vimming 🙂

UPDATE
These files are now available from my github dotfiles repository, including the gem inside of the vim/gems_required directory.

Previous

Slides from REST Talk at St George Bank

Next

Linux VirtualBox vs Windows for Rails Dev

5 Comments

  1. These instructions were really helpful! But I think it’s supposed to be ~/.vim/plugin (withtout the trailing s) isn’t it? I had to do that before it worked for me. I dunno, i’m not a plugin ninja.

  2. Thanks, that’s right! I’ll update the post.
    James

  3. skrv

    Thanks for the instructions, currently I am using gvim on windows.

    I have a problem – my fuzzyfinder isnt working
    when i press f it says command fuzzyfindertextmate not found. i have correctly put the plugins in the plugins directory of vim73/plugins and vimfiles/plugins, as I was not sure what directory it will use.

    Any guess as to what might be the problem or is there a way to find/debug plugins sourcing into givm.

    Thanks,
    Sawan

  4. Hi Sawan, you might want to check if Ruby is on your path and if the gem is installed correctly (gem list –local).

  5. skrv

    Got FuzzyFinder working, but the

    FuzzyFinderTextMate isnt working, Ruby is in path it has some code conversion issue?

    Thanks,
    Sawan

Powered by WordPress & Theme by Anders Norén