vim and vundle on Ubuntu 16.04
Sep 21, 2016
warning
This post is more than 5 years old. While math doesn't age, code and operating systems do. Please use the code/ideas with caution and expect some issues due to the age of the content. I am keeping these posts up for archival purposes because I still find them useful for reference, even when they are out of date!
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):
" ~/.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 :
- 
    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' - 
    Add configuration information (if there is any) for the plugin at the end
    of the 
~/.vimrc - 
    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 completed, you should get a Done!* in the lower-left corner. Close the tab and you are done--: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:
" ~/.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:
- 
      The gruvbox plugin is added, under the vundle plugin, using 
      
Plugin 'morhetz/gruvbox' - 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) at the end of the code above
 - 
      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:
- 
    Add the lightline plugin
    
Plugin 'itchyny/lightline.vim' - 
    On both Ubuntu 14.04 and 16.04 I've had to add the
    
`laststatus=2fix to get the status line to show properly. At the end of the~/.vimrcfile, add:" lightline fix
set laststatus=2 
  3. 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:
- 
      Add the NERDTree plugin
      
Plugin 'scrooloose/nerdtree.git' - 
      If you'd like to assign 
control-nto open and close the file browser, add the following to the end of your~/.vimrc:" NERDTree shortcut
map <C-n> :NERDTreeToggle<CR> - 
      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 {% sbUrl refs["vim-template"] %} 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:
- 
      Add the vim-template plugin
      
Plugin 'aperezdc/vim-template' - 
      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" - 
      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:
- 
      Add the jedi-vim plugin:
      
Plugin 'davidhalter/jedi-vim' - 
      No configuration lines in 
~/.vimrcare needed. - 
      Finally, relaunch vim and run 
:PluginInstall. 
Once this is installed, the two commands I use all the time are:
- 
      
control-space: attempts to autocomplete - 
      
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:
- 
      Add the editorconfig plugin
      
Plugin 'editorconfig/editorconfig-vim' - 
      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 - 
      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.