How to keep your Vim Plugins up to date

words by Brian Racer

It’s not too hard to learn something new everyday about vim, but did you know there is an easy way to keep your plugins up-to-date? GetLatestVimScripts is a plugin that can do just that. You can grab the latest version from the webpage, but it’s most likely your distributions vim package already has it (Debian, Redhat, OSX, and MacPorts do anyway – check /usr/share/vim/vim72/plugin).

How does it know where to find updates? Either we manually add information about each of our plugins to a special config file, or plugin authors can embed a special comment in their scripts to be update friendly:

$ head ~/.vim/plugin/rails.vim
" rails.vim - Detect a rails application
" Author:       Tim Pope [email protected]
" GetLatestVimScripts: 1567 1 :AutoInstall: rails.vim
" URL:          http://rails.vim.tpope.net/

" Install this file as plugin/rails.vim.  See doc/rails.txt for details. (Grab
...

The bold-ed line will tell the plugin where to find updates. More on that in a minute. First lets create the directory where updates will be downloaded, and a configuration file will be placed:

mkdir ~/.vim/GetLatest
touch ~/.vim/GetLatest/GetLatestVimScripts.dat

By default the plugin will only download the updates and not install them. To enable auto-install put the following in your .vimrc:

let g:GetLatestVimScripts_allowautoinstall=1

Now run :GetLatestVimScripts or :GLVS. Vim will analyze your plugins, see if they contain information about their download location, and add it to the .dat file. Then it will wget the plugins and install them. If you had any plugins that were update friendly, they are now updated to the latest version! Since not all plugins are update friendly, you may have to manually add lines to the GetLatest/GetLatestVimScripts.dat. The format looks like this:

ScriptID SourceID Filename
--------------------------
294 10110 :AutoInstall: Align.vim
1896 7356 :AutoInstall: allml.vim
1066 7618 :AutoInstall: cecutil.vim
1984 11852 :AutoInstall: FuzzyFinder
1984 11852 :AutoInstall: fuzzyfinder.vim
1567 11920 :AutoInstall: rails.vim
1697 8283 :AutoInstall: surround.vim

The first two lines act as comments but are required, so don’t remove them! Next is the ScriptID which is the script_id url parameter on the plugin’s vim.org webpage (ex: http://www.vim.org/scripts/script.php?script_id=642). Then there is the SourceID which is a url parameter which identifies the version of the plugin (ex: http://www.vim.org/scripts/download_script.php?src_id=8283). The ScriptID is what is compared for newer versions. If you are adding a new plugin, you can just set it to 1, run an update, and the number will automatically be set to the latest version. :AutoInstall: is a flag that signifies the update should be installed after download, and lastly Filename is just the filename of the plugin.

GetLatestVimScripts.dat is an example of my update configuration. Also checkout my vimfiles and dotfiles git repos for more vim and shell scripts you might find useful!


Pimp your $PS1 with source control information

words by Brian Racer

I recently found a useful tip of appending source control information of the current working directory to your shell’s $PS1 line. It might look something like the following image:

The method I saw suggested using vcprompt, a small program that outputs a short string basic version control info. Although it worked well, there were a couple issues I had with it. First, it’s subversion support was somewhat lacking. Second, it was written in C which made it more of a pain to modify, and I wasn’t a huge fan of keeping the binary in version control.

After a little searching I stumbled across vcprompt.py, a python script that did the same thing. This version also had wider support for source control systems, and being a standard python text script it was something I could easily modify and put into my dotfiles git repo. I wasn’t happy with how this one displayed subversion information either(just a revision number which I didn’t find very helpful), so I made my own modification to display the branch you are in. Please pardon my lacking Python skills.

Anyway, on to pimping your prompt. Before we modify the PS1 variable, we need to make sure the vcprompt.py is in your $PATH. I like to put scripts like this in a custom bin directory in my homedir. One way to accomplish that might be the following:

$ mkdir -p ~/bin
$ cd ~/bin
$ wget http://github.com/anveo/dotfiles/raw/master/scripts/vcprompt.py
$ chmod +x vcprompt.py
$ export PATH=~/bin:$PATH

Displayed next is the PS1 line I use – it takes up two lines: the first line contains the current user, hostname, current working directory, and possibly version control info, and the second is just a nice looking arrow for my input. Your terminal will need to support Unicode if you want to use that symbol.

# .bashrc
PS1="\n\u@\h:\w \[\e[1;30m\]$(vcprompt)\[\e[0m\] \n→"
 
# If you are using zsh you may also need the following in .zshrc
setopt prompt_subst

If you use the colors specified, you may need to define those too.

You should now have a prompt similar to the image above! For more shell customizations checkout the rest of my dotfiles, and consider buying Peepcode’s Advanced Command Line screencasts for more productive tips!


Learning Haml/Sass? Try Rendera!

words by Brian Racer

Fellow ECRuby group member Brian Hogan has released Rendera, a great web-based tool to learn Haml and Sass markup interactively in your browser. You can paste in your HTML/CSS code and it will convert to Haml and Sass, and vice versa. It also includes a number of interesting preset examples to study – a few exploiting some very cool HTML5 features. Check it out!

(and if you haven’t checked out Haml or Sass yet, please do!)