Hacker News new | ask | show | jobs
by dredmorbius 2392 days ago
You can bind dict to the "keywordprg" query key ('K') in vim.

By default, that's tied to 'man', which lets you look up a particular command in the system manpages. Swap that to dict for text files (say, filetype markdown or HTML), and you've now got a dictionary lookup for any given word. Not sure of spelling or meaning? Position cursor on word and hit 'K', and you'll get the word's definition, or a match of near-spellings.

The dict database can also be extended to other datasets -- anything with a keyword-result relationship. On Debian, this includes the US Census "Tiger" files (thanks to Bruce Perens for buying a copy and sharing them to the project), which lets you look up any specific city or place name in the United States.

You can specify the dictionary you want to use on the commandline, or write a shell alias or function to query a specific database, say:

    dictzip () { /usr/bin/dict -d gaz2k-zips "$*" | ${PAGER:-less}; }
    dictplace () { /usr/bin/dict -d gaz2k-places "$*" | ${PAGER:-less}; }
Which allows you to query ZIP Codes or place names without otherwise mentioning the dictionary on the commandline.

There are numerous other query tools bundled together in tools such as surfraw(1) (https://packages.debian.org/buster/surfraw), with 123 separate query targets.

Or you can write your own. I've got a wrapper around the NOAA's weather six-day forecast page which dumps a text-formatted version of just the forecast text (a lot of ugly sed and awk). Having to write programmes to remove the text other programmes lard onto a simple data request is Where We Are Now in Today's WWW.

Or a lookup for the Online Etymological Dictionary:

    etym () { \w3m -T text/html "https://www.etymonline.com/word/${1}"; }
(w3m is escaped '\' to byapass the alias I've defined, 'alias w3m="w3m -B"', which defaults to opening my bookmarks file if no argument is given.)

Learning what you're typing, and what it does, and what the underlying logic are, is much of the fun.