Install and setup vim on Ubuntu 14.04

<note> I have upgraded to Ubuntu 16.04 and wrote another post about setting up vim, this time using vundle instead of pathogen. Checkout the new post– vim and vundle on Ubuntu 16.04 – if that sounds interesting to you. </note>

Vim is a powerful editor that can be used on your laptop/desktop and is also typically found of any Linux server you might encounter. As a result, I started using vim as my main editor. The Ubuntu install is simple:

$ sudo apt-get install vim

That’s it, you’re ready to edit. A good place to start if you need to learn more about vim is the main website: vim . Also be sure to check out the vim tutorials.

Pathogen

My next step is to add a variety of vim plugins that make (my) life easier. To do this I use pathogen a wonderful vim package manager. Installation is accomplished with the following lines:

$ mkdir -p ~/.vim/autoload ~/.vim/bundle;
$ curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

If you don’t have curl installed, use:

$ sudo apt-get install curl

and try the second line again. Finally, if you don’t have a ~/.vimrc file create the following minimal example:

" contents of minimal .vimrc
execute pathogen#infect()
syntax on
filetype plugin indent on

NERDTree

NERDTree is a plugin the provides a nice file browser with bookmarks. With pathogen available, getting NERDTree installed is as simple as:

$ cd ~/.vim/bundle
$ git clone https://github.com/scrooloose/nerdtree.git

After installing, start vim and type:

:NERDTreeToggle

to toggle the file browser open or closed. Use up and down arrows to select files and press enter to open file in current tab. To open in a new tab, select the file and press t.

To bookmark, select a directory and type:

:Bookmark bookmarkname

to assign bookmarkname to the desired directory. To toggle the bookmarks open or closed (while in the NERDTree window) press shift-b. Finally, to open a bookmark, select the bookmark using up/down arrows and press enter when the desired bookmark is highlighted.

Tagbar

Tagbar does a nice job of showing code outlines– class, methods, etc and allows for jumping to different parts of the code using the outline. I’ve mainly used this with Python, where the results are very nice.

First, we have to install exuberant ctags , which Tagbar uses to do its parsing. Luckily, there is version in the Ubuntu repository:

$ sudo apt-get install exuberant-ctags

Next, install the vim plugin using pathogen, as before:

$ cd ~/.vim/bundle
$ git clone git://github.com/majutsushi/tagbar

Thanks to pathogen, we can now start vim and type:

:TagbarToggle

to toggle the code outline open or closed. To get to the code outline window press Cntrl-w and then l – this is a general vim command to move to the right window. Use up and down arrows to move through the code outline. When the desired class or function is highlighted press enter and vim will jump to the desired code. This is very nice for larger files!

jedi-vim

Next we install the jedi-vim plugin which allows for auto-complete and documentation search for Python projects. First, we install the Python package jedi

$ pip install --user jedi

I use this command assuming that you are installing all python packages as a user. Otherwise you will have install with $ sudo pip install jedi (global install), or activate the desired virtual environment and use $ pip install jedi.

Finally, use pathogen to install jedi-vim in the usual way:

$ cd ~/.vim/bundle/
$ git clone https://github.com/davidhalter/jedi-vim.git

The two command I use most with jedi are:

  • cntrl-space : auto-complete
  • shift-k : get documentation (must be in command-mode and put cursor on function of class of interest)

vim-template

vim-template is a plugin that provides nice file templates for new files. Using pathogen the installation is simple:

$ cd ~/.vim/bundle
$ git clone git://github.com/aperezdc/vim-template.git

Now, try:

$ vim test.py

or,

$ vim test.sh

to see the standard templates for Python files and bash scripts, respectively.

There are a variety of customizations that can be made (see the link above), but I like to add the following defaults to my .~/vimrc file:

" Customize the settings for vim-template plugin
let g:email = "desiredemail@gmail.com"
let g:user = "Desired Name"
let g:license = "Desired License"

That’s it for my basic vim and vim-plugins setup. Questions and comments are always welcome.

Tags

api [1]   arduino [1]   audio [2]   audio features [1]   babel [1]   Bayesian [7]   Beta [1]   blog setup [1]   bootstrap [1]   bottleneck [1]   c++ [1]   caret [1]   cmpy [1]   conditional probability [6]   coursera [1]   coursera intro to data science [3]   css [1]   cython [1]   d3 [2]   decision trees [2]   diy [1]   dropbox [1]   dsp [1]   e1071 [1]   essentia [1]   garmin [1]   geojson [1]   ggplot2 [1]   gis [2]   git [1]   gnuplot [1]   graphs [1]   html5 [1]   igraph [1]   ipython [1]   javascript [7]   joint probability [6]   json [1]   LaTeX [2]   LDA [1]   Lea [2]   machine learning [3]   marginal probability [6]   matplotlib [1]   meteor [2]   mir [1]   MongoDB [3]   music [2]   my python setup [5]   my ubuntu setup [10]   mysql [3]   networks [1]   networkx [1]   nodejs [5]   npm [3]   numexpr [1]   numpy [1]   octave [1]   Open Oakland [2]   openpyxl [1]   pandas [3]   patsy [1]   pip [2]   pweave [1]   pygraphviz [1]   pymc [1]   PySoundFile [2]   python [15]   Python [1]   python 2.7 [5]   python 3.4 [2]   pyyaml [1]   qgis [1]   R [1]   randomForest [1]   restview [1]   resume [1]   rpart [1]   running [1]   scikit-learn [3]   scipy [1]   screen [1]   server setup [1]   shapefile [1]   social networks [1]   Socrata [1]   sound [2]   sphinx [1]   sql [4]   sqlite3 [1]   ssh [1]   ssh keys [1]   statsmodels [1]   supervised learning [2]   sympy [1]   tableau [1]   tinkerer [2]   topic models [1]   tree [1]   ubuntu 14.04 [13]   Ubuntu 14.04 [3]   ubuntu 16.04 [4]   vim [2]   virtualbox [1]   virtualenv [4]   virtualenvwrapper [3]   VPS [1]   vundle [1]   webpack [1]   yaml [1]