Enhancing your Vim in Ubuntu!

NOTE: This tutorial is for the people using Ubuntu 12.04 or above.

Hello and welcome to this tutorial for enhancing your favourite text editor Vim. ^_^
For those who don’t know what Vim is, check out its official website or this wikipedia page.

And those who are already familiar with it, lets advance to enhance. 😀
Lets see what we are going to do today. We will be updating our VIm with a plugn known as YouCompleteMe (YCM).

YouCompleteMe is a fast, as-you-type, fuzzy-search code completion engine for Vim. It has several completion engines: an identifier-based engine that works with every programming language, a semantic, Clang-based engine that provides native semantic code completion for C/C++/Objective-C/Objective-C++ (from now on referred to as “the C-family languages”), a Jedi-based completion engine for Python, an OmniSharp-based completion engine for C# and an omnifunc-based completer that uses data from Vim’s omnicomplete system to provide semantic completions for many other languages (Ruby, PHP etc.).
Source: http://valloric.github.io/YouCompleteMe/

Ok now moving on first we ensure that our Vim is compatible for this plugin.
Open your Vim, if not installed then you can skip this step, type
:version

If the version of the Vim is atleast 7.3.584 then its fine otherwise you may have to build it from source which is very easy to do.
So if you found out that your version of Vim is not upto-the-mark, then we have to remove it first before building it again.
Run the following commands in your terminal:
sudo apt-get remove vim vim-runtime gvim
and also
sudo apt-get remove vim-tiny vim-common vim-gui-common
These will remove the Vim installation from your system.

Now the next step is to build it from the source. Run these commands:
cd ~
hg clone https://code.google.com/p/vim/
cd vim
./configure --with-features=huge \
--enable-rubyinterp \
--enable-pythoninterp \
--enable-perlinterp \
--enable-gui=gtk2 --enable-cscope --prefix=/usr
make VIMRUNTIMEDIR=/usr/share/vim/vim74a
sudo make install

We have now successfully build the newer version of Vim on our system and now the next step is to install YCM plugin.
Type :echo has('python') in Vim. The output should be 1. This tells us that our Vim has Python support which is required for our plugin.

Now we will install YCm using Vundle. Its a Vim plugin manager.
To download Vundle run the following commands:
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
and then we must configure our bundles in .vimrc file. If you can’t find the file in your home folder then you may need to create it with following content:

set nocompatible ” be iMproved
filetype off ” required!

set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

” let Vundle manage Vundle
” required!
Bundle ‘gmarik/vundle’

” My Bundles here:

” original repos on github
Bundle ‘tpope/vim-fugitive’
Bundle ‘Valloric/YouCompleteMe’
Bundle ‘Lokaltog/vim-easymotion’
Bundle ‘rstacruz/sparkup’, {‘rtp’: ‘vim/’}
Bundle ‘tpope/vim-rails.git’
” vim-scripts repos
Bundle ‘L9’
Bundle ‘FuzzyFinder’
” non github repos
Bundle ‘git://git.wincent.com/command-t.git’
” git repos on your local machine (ie. when working on your own plugin)
Bundle ‘file:///Users/gmarik/path/to/plugin’
” …

filetype plugin indent on ” required!

” Brief help
” :BundleList – list configured bundles
” :BundleInstall(!) – install(update) bundles
” :BundleSearch(!) foo – search(or refresh cache first) for foo
” :BundleClean(!) – confirm(or auto-approve) removal of unused bundles

” see :h vundle for more details or wiki for FAQ
” NOTE: comments after Bundle command are not allowed..

You can see that I’ve added a bundle for YCM too.
Now open your Vim and run
:BundleInstall

This will install all the bundles. 🙂

And we are done! ^_^
Enjoy!
Note:
If you get the ycm_core library not compiled error then you need to recompile it by following commands.
cd ~/.vim/bundle/YouCompleteMe
./install.sh --clang-completer

Also ensure that you have python headers installed if not then install by
sudo apt-get install python-dev

Advertisements

One thought on “Enhancing your Vim in Ubuntu!

  1. Wish it were so simple for me. I had to compile ycm, put in .ycm.*.py files, switch switches, and still it was raw and seemed to fight with UltiSnips. I took it out after an hour.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s