How to Use Gists to Show Code Snippets

You don’t need to make a new Gist for each code snippet. Instead, display a single file from a multi-file Gist

Luke Gloege, Ph.D.
2 min readApr 19, 2021
Photo by Luke Chesser on Unsplash

A GitHub Gist is arguably the best way to display code snippets in a Medium post. Syntax highlight alone makes it the ideal choice. A Gist will typically consist of multiple files, which inevitably leads to the question: how do I display an individual file? Unless you're a web developer, the answer is not obvious. This post will answer that question.

You can select a file from a Gist with multiple files by appending the URL with: ?file=fileName

Basics: how to insert a Gist

To insert a Gist into your post, simply copy the URL into the Medium editor and hit enter. Voila, you have some nicely formatted code displayed.

The code above was displayed using the following URL:

--

--

Luke Gloege, Ph.D.
Luke Gloege, Ph.D.

Written by Luke Gloege, Ph.D.

Postdoctoral Research Associate @Yale | Climate Scientist | Python programmer | Dog dad