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
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
$ cd ~/.vim/bundle $ git clone https://github.com/scrooloose/nerdtree.git
After installing, start vim and type:
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:
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 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.
$ sudo apt-get install exuberant-ctags
$ cd ~/.vim/bundle $ git clone git://github.com/majutsushi/tagbar
Thanks to pathogen, we can now start vim and type:
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!
$ 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)
$ cd ~/.vim/bundle $ git clone git://github.com/aperezdc/vim-template.git
$ vim test.py
$ 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 = "firstname.lastname@example.org" 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.