Gist, a Pastebin-type service from Github, is really useful and powerful for folks who like to collaborate using git. Vim users can "kick it up a notch," with the Gist.vim script for Vim.

If you use git to collaborate, you probably also know about Gist, a Pastebin-type service from Github. But did you also know, that if you're a Vim user you can get even more out of it with the script Gist.vim?

If you're working on text that you'd like to post to Gist or you want to work on text that's already on Gist, you can do so without leaving Vim or disrupting your workflow.

To get started, grab the script ( gist.vim ) and copy it to your ~/.vim/plugin directory. You'll also need a Gist account and configure git with your account details. You'll need your username and your Github token. You can find the token under Account Settings -> Account Admin. You can configure the account details a few ways; I prefer to use the git configuration:

git config --global github.user username git config --global github.token token

Once your account details are set up, go ahead and fire up Vim. To post to Gist, simply run the command :Gist , which will post the entire buffer in Vim to Gist. To paste a selection to Gist, use Vim's visual mode to select text and then enter command mode and run the Gist command. You can also specify a range manually. If you wanted to copy lines 9 through 18, you'd run 9,18 Gist or specify the range to the current line with 9,. Gist instead.

When you've pasted a piece of text to Gist, the URL for the new Gist will be displayed in Vim's status line.

To see a list of your Gists, run Gist -l . This will display a list that looks like the following:

gist:XXXXX------------------------------------ gist:XXXXX------------------------------------ gist:XXXXX------------------------------------ gist:XXXXX------------------------------------

The XXXXX is the number of the Gist. Hit Enter on any of the lines, and Vim will open them in a new buffer. You can then edit the buffer and write it back to Gist. Hence, you can use Vim to revise files hosted on Gist without saving them locally.

You can also get Gists that are not associated with your account if you have their Gist number. Run :Gist XXXXX , and Vim will fetch the Gist (assuming it's public, of course).

If you're working on something you don't want publicly listed, you can save it privately using :Gist -p . These won't show up when using the -l option for Gist, but you can retrieve a private Gist using the long string associated with the private Gist.

Gist.vim is a simple but very useful tool. See the Gist page for the rest of the Gist script commands.

Joe 'Zonker' Brockmeier is a freelance writer and editor with more than 10 years covering IT. Formerly the openSUSE Community Manager for Novell, Brockmeier has written for Linux Magazine, Sys Admin, Linux Pro Magazine, IBM developerWorks, Linux.com, CIO.com, Linux Weekly News, ZDNet, and many other publications. You can reach Zonker at jzb@zonker.net and follow him on Twitter.

Follow ServerWatch on Twitter