vim and vundle on Ubuntu 16.04

I have just upgraded to Ubuntu 16.04, the new long-term-stable distribution of Ubuntu. This means I will be installing all of my trusted computing tools on this new distribution as well as reconsidering some of my approaches. In this post I’ll go over a new approach to my vim setup for Ubuntu 16.04, changing from pathogen to vundle plugin management.

overview

In a previous post, Install and setup vim on Ubuntu 14.04, I described installing vim and using pathogen to manage vim plugins on Ubuntu 14.04. Over the past two years I have used pathogen without trouble and expect the same would be true on Ubuntu 16.04 – so, checkout the previous post if you’d like to use pathogen.

In this post I’ll cover using vundle to manage my plugins– this is mainly out of curiosity to try out a new tool. However, there is one advantage that I like: the vim plugins I’m using are recorded in my ~/.vimrc file, making it easy to reinstall plugins on a new machine. This is a nice benefit of the vundle approach.

vim

So let’s get started with installing vim

$ sudo apt-get install vim

That’s it, now to the plugins.

vundle

First up is vundle, of course, because this has to do all the managing. The file ~/.vimrc and the directory ~/.vim are where all the action happens. If you have them, it’s good to backup. For example, following this nice Digital Ocean Tutorial on vundle, one can use:

$ if [ -e .vimrc ]; then mv .vimrc .vimrc_bak; fi
$ if [ -e .vim ]; then mv .vim .vim_bak; fi

Once you are backed up, the vundle git repository can be cloned using:

$ git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

Next, create a minimal ~/.vimrc file to get things started:

$ vim ~/.vimrc

This file should contain the following (also checkout the examples at the vundle repository):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
" ~/.vimrc
"

" no vi compat
set nocompatible

" filetype func off
filetype off

" initialize vundle
set rtp+=~/.vim/bundle/Vundle.vim

call vundle#begin()
" start- all plugins below

Plugin 'VundleVim/Vundle.vim'

" stop - all plugins above
call vundle#end()

" filetype func on
filetype plugin indent on

This loads the vundle plugin itself and establishes the basic layout of the ~/.vimrc file. After the file is saved, relaunch vim and run

:PluginInstall

This process is the same for adding any new plugin using vundle:

  1. Add the repository for the plugin to your ~/.vimrc. Be sure that this addition is in the designated area: lines 15-17 in the example above. The addition of the vundle repository is an example of the correct format:
Plugin 'VundleVim/Vundle.vim'
  1. Add configuration information (if there is any) for the plugin at the end of the ~/.vimrc
  2. Relaunch vim and run :PluginInstall, as described above. This will run through all the plugins listed and install any that are not setup– in the process, a new tab is opened to describe the process. When done you should get a Done! in the lower-left corner. Close the tab and you are done– use :q.

I’ll add the gruvbox plugin very explicitly as the next example and then move to a more abbreviated description of the process.

gruvbox

First, let’s get some color– I like the gruvbox dark color scheme. There are a bunch of other choices out there so don’t feel obligated to use my favorite! More to point, I’ll use the installation of gruvbox as a detailed example of adding a plugin using vundle.

As discussed above, to install the plugin we modify our ~/.vimrc. We add the gruvbox repository information and add some plugin-specific details at the end of the file. After the changes, the ~/.vimrc file looks like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
" ~/.vimrc
"

" no vi compat
set nocompatible

" filetype func off
filetype off

" initialize vundle
set rtp+=~/.vim/bundle/Vundle.vim

call vundle#begin()
" start- all plugins below

Plugin 'VundleVim/Vundle.vim'
Plugin 'morhetz/gruvbox'

" stop - all plugins above
call vundle#end()

" filetype func on
filetype plugin indent on

" set color
colorscheme gruvbox
set background=dark
set colorcolumn=80

In summary, the changes/actions are:

  1. [line 17] The gruvbox plugin is added
  2. [lines 25-28] I’ve set gruvbox as the colorscheme, chosen the dark background, and set column 80 as the color column (this makes the column a lighter gray by default)
  3. Relaunch vim and run :PluginInstall. After a relaunch of vim you should have the nice gruvbox dark theme working.

lightline

Next, I will install lightline, a nice status line for vim. I use the default settings, but there are a bunch of customizations that can be done– checkout the lightline repository for more information. The changes are:

  1. Add the lightline plugin
Plugin 'itchyny/lightline.vim'
  1. On both Ubuntu 14.04 and 16.04 I’ve had to add the laststatus=2 fix to get the status line to show properly. At the end of the ~/.vimrc file, add:
" lightline fix
set laststatus=2
  1. Finally, relaunch vim and run :PluginInstall.

NERDTree

NERDTree is another essential vim plugin, providing a nice file browser to find and open files as well as bookmark directories. The install goes as follows:

  1. Add the NERDTree plugin
Plugin 'scrooloose/nerdtree.git'
  1. If you’d like to assign Cntl-n to open and close the file browser add the following to the end of your ~/.vimrc
" NERDTree shortcut
map <C-n> :NERDTreeToggle<CR>
  1. Finally, relaunch vim and run :PluginInstall.

The bookmark feature in NERDTree still works as I described previously, so check that post out if you’d like to use that feature– Install and setup vim on Ubuntu 14.04.

vim-template

If you’d like to have file templates with vim a useful plugin is vim-template. Using this tool, starting up vim like so:

$ vim test.py

will produce a file that looks like (after some config):

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2016 Your Name <Your Email>
#
# Distributed under terms of the Your-License license.

"""

"""

Using the usual vundle install process, do the following:

  1. Add the vim-template plugin
Plugin 'aperezdc/vim-template'
  1. Set the template fills for name, email, etc. by adding the following to the end of your ~/.vimrc (of course change to relevant information):
" Customize the settings for vim-template plugin
let g:email = "Your Email"
let g:user = "Your Name"
let g:license = "Your-License"
  1. Finally, relaunch vim and run :PluginInstall.

jedi-vim

If you are a Python coder, jedi-vim is a great plugin allowing for autocompletion and pulling up documentation inside of vim. However, this plugin depends on installing the Python package jedi. This can be done a variety of ways, I use pip:

$ pip install --user jedi

This installs the most recent version of jedi. Once this is installed the vundle install of the vim plugin goes as usual:

  1. Add the jedi-vim plugin
Plugin 'davidhalter/jedi-vim'
  1. No configuration lines in ~/.vimrc are needed.
  2. Finally, relaunch vim and run :PluginInstall.

Once this is installed, the two commands I use all the time are:

  1. cntl-space: attempts to autocomplete
  2. shift-k: attempts to load documentation into a new vim window. This must be done in command-mode with the cursor on the function or class of interest.

editorconfig

A relatively new addition in my vim workflow is editorconfig, which lets the user store editor configurations like the size of indent, whether to use tab or space, etc. These configurations files can be set globally and per-project– also, the settings can be used by a bunch of editors, not just vim. You should checkout the editorconfig site to learn more and choose your settings.

The vim install is:

  1. Add the editorconfig plugin
Plugin 'editorconfig/editorconfig-vim'
  1. The are no settings in ~/.vimrc, but my global configuration is contained in a file, ~/.editorconfig (at time of this post):
# EditorConfig is awesome
# http://EditorConfig.org
root = true

# defaults
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true

# md
trim_trailing_whitespace = false

# py
[*.py]
indent_size = 4

# Tab indentation (no size specified)
[Makefile]
indent_style = tab
  1. Relaunch vim and run :PluginInstall.

That’s it

So, that’s it for my (self-) documentation of getting started with vundle on Ubuntu 16.04. Hopefully those who find this post will find it helpfull– I know I’ll look back at it when I have to upgrade to Ubuntu 18.04 in a couple of years.

If you find typos or have a question please leave comments below. I’ll do my best to respond in a timely manner. I would also love to read about other useful plugins or different approaches to what I’ve done– again, leave a note below.

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]