Dictionary

A plugin providing in-editor dictionary access in Sublime Text.

Code Downloads Package Control Page View More Plugins

Overview

Dictionary is a Sublime Text plugin I developed to provide easy access to a dictionary directly inside the Sublime Text editor. Using the Free Dictionary API, the plugin allows users to easily look up information about words. Since I published the plugin on Package Control, Dictionary has been installed over 2,000 times, making it one of my most popular plugins.

Motivation

In addition to writing code, I also used Sublime Text to read and edit text files. These ranged from README and markdown files to other text documents like a diary and learning notes. At times, I encountered unfamiliar words while reading texts inside Sublime Text.

At first, each time this happened, I would switch to a web browser and look up the word. Then, I’d return to Sublime Text to continue my work.

This worked, of course, albeit with some disruption to my workflow. However, I thought: among the thousands of packages made for Sublime Text, there had to be a plugin for looking up words. As it turned out, there wasn’t one that I could use. I found plugins for translating between languages, spell-checking, and even autocompleting words. There was a dictionary plugin that matched what I was looking for, but it only works on macOS (I was still using Windows machines then).

Without an existing solution, I decided to get to work and build my own. The result is the Dictionary plugin.

How It Works

Dictionary information is displayed in a popup opened by the plugin. It is triggered when a user clicks on or selects a word and runs the dictionary_define command either via a keyboard shortcut or through the Dictionary: Define option in the command palette.

The dictionary_define command first cleans the text using regex, extracting the first group of alphanumeric characters so as to remove symbols and whitespace characters.

Then, an API call is made to the Free Dictionary API. Python’s built-in urllib module is used instead of a third-party library like requests because Sublime Text’s embedded Python interpreter comes with standard library modules like urllib. Using a third-party package would have required extra bundling, increasing the size of the plugin installation. After the API call, relevant fields are extracted from the data and shown to the user via a popup next to the word itself.

Demo

Customization

There are currently 2 ways in which users can customize the Dictionary plugin.

Firstly, the plugin has a hover mode. When the hover_mode setting is set to true, dictionary definitions are shown whenever the user hovers their cursor over some text without the need to run the dictionary_define command. Hover mode can be toggled via the Dictionary: Toggle Hover Mode (dictionary_toggle_hover_mode) command in the command palette or in the settings file.

Secondly, the num_definitions setting configures the maximum number of definitions that should be displayed for each word.

Early versions of the plugin supported multiple languages, which could be customized in the settings. However, changes made to the Free Dictionary API means only English definitions are now available.

Learn More

The code for this plugin can be found here. Its Package Control listing is located here.

To learn more about my other Sublime Text plugins, visit this page.