Setting up VIM for Rails Development 27 May 2012

Here is a list of some of the tools we need, to use Vim for Rails Development or for any software development for that matter.

  • File browser
  • Quickly Open Files
  • Searching
  • Goto method definitions
  • Snippets
  • Commenting

Install VIM

  sudo apt-get install vim vim-gnome vim-gui-common

Setting up Directories

mkdir ~/vim
mkdir ~/vim/bundle
mkdir ~/vim/autoload
ln -s ~/vim ~/.vim
cd ~/vim
touch vimrc
touch gvimrc
git init

VIM Plugins

Pathogen

Pathogen is a plugin manager for Vim.

curl -so autoload/pathogen.vim https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim

Add the following to ~/vim/vimrc

call pathogen#infect()

NerdTree (File browser)

A tree explorer plugin for navigating the filesystem

git submodule add https://github.com/scrooloose/nerdtree bundle/nerdtree

Command-T (Quickly Open Files)

Fast file navigation for VIM

sudo apt-get install ruby1.8 rubygems1.8
sudo gem install bundler
git submodule add https://github.com/wincent/Command-T.git bundle/command-T
cd bundle/commant-T
bundle install
rake make

Usage:
Goto your project folder and use “Leader t”.

Plugin for the Perl module / CLI script ‘ack’

sudo apt-get install ack-grep
git submodule add https://github.com/mileszs/ack.vim.git bundle/ack

Usage:
Ack config
This will search for the word config in your project.
Use :cn and :cp to navigate between search results

Ctags (Goto Method Definition)

sudo apt-get install exuberant-ctags
ctags -R --exclude=.git --exclude=.svn --exclude=log *

Usage:
Run the above command in your project folder. This will generate a tags file
To goto a definition of a method just take your cursor on the method and use Ctrl + ]
To go back to previous position use Ctrl + o

Snipmate (Code Snippets)

git submodule add https://github.com/garbas/vim-snipmate bundle/snipmate

Snipmate Snippets

git submodule add https://github.com/honza/snipmate-snippets bundle/snipmate-snippets

Usage:
Use Tab after entering the snippet shortcut

TComment (Comment blocks of code)

git submodule add https://github.com/tomtom/tcomment_vim.git bundle/tcomment

Usage:
Select a block and use gcc to comment the block.
Use gc to comment current line

Rails.vim

git submodule add git://github.com/tpope/vim-rails.git bundle/vim-rails

Fugitive (Git from Vim)

git submodule add https://github.com/tpope/vim-fugitive.git bundle/fugitive

Color Schemes

git submodule add https://github.com/squil/vim_colors.git bundle/colors

Finally Commit to Github

git add .
git commit -m "Vim configutation packages"
git remote add origin git@github.com:anupnivargi/vim.git
git pull origin master
git push origin master

Next time you can clone this repository and get started with your development

Happy Editing.

Thoughts

comments powered by Disqus