SHARE
Facebook X Pinterest WhatsApp

Get More Out of Git: Use Gist With Vim

Written By
thumbnail Joe Brockmeier
Joe Brockmeier
Apr 18, 2011
ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More



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

thumbnail Joe Brockmeier

Joe Brockmeier is the editorial director of the Red Hat Blog. He joined Red Hat in 2013 as part of the Open Source and Standards (OSAS) group, now the Open Source Program Office (OSPO). Prior to Red Hat, Brockmeier worked for Citrix on the Apache OpenStack project, and was the first OpenSUSE community manager for Novell between 2008-2010. Brockmeier also has an extensive history in the tech press and publishing, having been editor-in-chief of Linux Magazine, editorial director of Linux.com, and a contributor to LWN.net, ZDNet, UnixReview.com, and many others.

Recommended for you...

What Is a Container? Understanding Containerization
What Is a Print Server? | How It Works and What It Does
Nisar Ahmad
Dec 8, 2023
6 Best Linux Virtualization Software for 2024
What Is a Network Policy Server (NPS)? | Essential Guide
ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.