Vim for Ruby on Rails Development - Match made in Heaven
If you’re a programmer who writes lots of code then it’s important to learn about your Editor.
Nowadays may be some of you are using editors like Sublime, Atom, Rubymine…etc but very few knows about the Vim.
Developers could be lazy and very clever at the same time. We’re able to customize our environment to make it work in a way we want it to work. We spend a lot of time in thinking about how to optimize these tasks because we don’t want to repeat ourselves over and over again. We try to make things with less efforts to get as much things as possible done. We want to be productive.
We can get this when we start to use vim. To get install vim on your Linux machine just type below command in your Terminal:
$ sudo apt-get update $ sudo apt-get install vim
After that just type vim and here you go.
VIM has several extension managers, but the one we strongly recommend is Vundle. It makes installing and updating packages trivial.
Let’s get Vundle installed:
$ git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
This command downloads the Vundle plugin manager and chucks it in your VIM bundles directory. Now you can manage all your extensions from the. vimrc configuration file.
Now make. vimrc configuration file from below command to your home directory:
$ cd $HOME $ vim. vimrc
Now set up Vundle in your. vimrc by adding the following to the top of the file:
That’s it. You’re now all set to use Vundle. Afterwards you can add the plugins you want to install, then fire up VIM and run:
Using Vim as a Complete Ruby on Rails IDE
I couldn’t possibly list all the VIM features, but let’s take a look at a quick list of some of the powerful out-of-the-box features perfect for Rails development.
Ditch the Mouse
Probably the MOST important feature of VIM is that it doesn’t require a mouse (except for the graphical variants of VIM). At first this may seem like a horrible idea, but after you invest the time – and it does take time – to learn the key combinations, you will speed up your overall workflow!
Now install plug-in for rails and for that Just add the following line inside thecall vundle#begin() and call vundle#end() block:
After this type :PluginInstall in vim and restart vim. Rails.vim will be ready to use.
Here are some cool stuff that you can use for rapid development.
Open a file with :sv <filename> and you split the layout vertically (e.g., the new file opens below the current file) or reverse the keys to :vs <filename> and you get a horizontal split (e.g., the new file opens to the right of your current file)
The same way you can split the view horizontally.
Want to perform basic git commands without leaving the comfort of VIM? Then vim-fugitive is the way to go:
By installing this plug-in you can perform all your Git operations with it. See below(Just one example):
Refactoring tool for Ruby in vim! To get this plugin add below to .vimrc file:
Call :PluginInstall and restart Vim.
There are lots of other extensions like
- Plugin ‘thoughtbot/vim-rspec’
- Plugin ‘garbas/vim-snipmate’
- Plugin ‘Xuyuanp/nerdtree-git-plugin’
Vim is highly customizable. You can customize vim as per your need.
That’s more or less it (for Ruby on Rails development, at least). There are a ton of other extensions that you can use, as well as alternatives to everything detailed in this post. What are some of your favorite extensions? How have you configured VIM to match your personality?
- VIM Tutor comes with VIM, so once VIM is install just type vimtutor from the command line and the program will teach you how to use VIM by, well, using VIM.
- VIMcasts are advanced tutorial videos describing how to use many of VIM’s features.
- Official VIM docs
- Open Vim
Do you, or do you know anybody who may benefit from our software development prowess!
At BoTree Technologies, we build enterprise applications with our RoR team of 25+ engineers.
Consulting is free – let us help you grow!
Choose Your Language
- Digital Marketing
- IT Consulting
- Project Management