Sublime text and github gists

Sublime text and github gist

In Sublime text there are big variety of useful tools, that help to write code. I've learned only a small part of them, currently i'm trying to write in Vintage mode (vim style cursor management). But now i want to tell about integration github gists with sublime text. If you don't now, github gists let you save snippets as a separate file without creation full repository. But it have many repository features - versions, possibility to fork.

What we'll have at the end.

Save snippet from sublime, give to it description with key words. Then again from sublime we can find snippet by key words and see it in editor. All snippets are saved in github, so they are avaliable from other computers.

Remember, that sublime text has its own snippet functionality. But it is more preferable for small auto insertion. For example, when you write def in python, insert function template:

    def function():

Github gist are more suitable for something bigger - some function for exact purpose.

Lets setup this functionality

Gist plugin setup

The easiest way to do it is with sublime package manager. Here is instruction for setup. In sublime press ctrl + shift + p, enter install and then gist:

install package
gist install

Give access to your github account.

Press Preferences->Package settigns->Gist->Settings User.

gist install

You can either set login + password, either token. If needed settings are not in Settings User, then they can be copied from Settings Default. But don't change default settings. To receive token, run in system command line (curl must be installed):

curl -v -u USERNAME -X POST --data "{\"scopes\":[\"gist\"]}"

where USERNAME - your github login

gist settings

Gist creation

Write code of your snippet in new sublime tab. I wrote code for taking content of csv file as list of lists. Press ctrl + shift + p, then gist create public and enter. Here is avaliable fuzzy searching, so i just enter public.

gist create

Give description to our snippet. It is important to include meaningful words, because search will use them. I write "Python: Get csv lines".

gist description

There will be also request for file name, it can be skipped by pressing enter.

Search for a gist.

Open sublime command line by pressing ctrl + shift + p and enter gist open.

gist open

Then enter key words "python csv"

gist find

And see our snippet.

gist opened

This snippet is also created at github:


Published: Jan. 3, 2013
Bookmark and Share

Follow-Up Articles

Comments powered by Disqus