How To Set Up A Light-Weight On-line Thesaurus For Vim Pt.II

09:00 Sat, 25 Feb 2012

Vim has support for a built-in thesaurus. However, it consumes memory and its auto-complete selection has issues. In Part I, I showed how to set up an on-line thesaurus. Here is how to build syntax rules that will colour the output.


This is the second post of two about a light weight way to implement a thesaurus. In Part I, I described how to set up a script that provides access to an on-line thesaurus. In this Part, I describe how to write a set of simple syntax rules to provide colour and highlighting for the output.

Here is a screenshot of the finished syntax rules (using dummy data):

highlighting screenshot


How To Set Up A Light-Weight On-line Thesaurus For Vim

08:02 Fri, 17 Feb 2012

Vim has support for a built-in thesaurus. However, it consumes a lot of memory, which you may not want for a feature you do not use much, and its auto-complete selection has issues. Here is how to set up an on-line thesaurus query that is light weight.


This is the first post of two (second here) about a light weight way to implement a thesaurus. It is great for what I need, which is the occasional use of a thesaurus for writing text such as this article. Once it is set up, you can forget about it and just use K whenever you want to look up a word.

A nice bonus or synergy of using an online source is that the website also returns a definition for the word, so it functions as a simple dictionary as well.

The second post (here) will deal with how to use Vim's built in syntax rule sets to provide highlighting and nice colours.


Calcc, A Programmers' Calculator

15:21 Fri, 13 Jan 2012

Calcc is a useful command line calculator for programmers, with a full range of bit and byte operators.

I have been going through James Malloy's tutorial on writing your own operating system1 , which involves some assembly and quite a bit of bit twiddling with shifts and masks in C.

I haven't written any assembly or done any serious bit manipulation for years. I can do simple (i.e. 1 byte) hexadecimal addition in my head, but nothing more complex than that, so I needed a quick calculator that showed me the results from doing things like bit shifts, rotates, masking, and so on.

A bit of googling found one contributor to Stackoverflow recommending calcc by Luigi Auriemma. A quick download of a small zip file and there it was, GPL'ed source code and pre-built binaries for unix and MS Windows.

It is quick and simple to use and has the usual unary and binary

Categories: programming, unix

John McCarthy

10:50 Tue, 25 Oct 2011

There must be something in the water. First Steve Jobs, then Dennis Ritchie, and now we have received word that John McCarthy has died. He was 84.

McCarthy was the inventor of Lisp, the concept of garbage collection, and coined the term "Artificial Intelligence". He even (unbeknowingly) forecast cloud computing through his notion of computing as a general public utility. Although probably not recognised by the general public, he was very much one of the pioneers of computer science. He received one of the very early Turing Awards, in 1971.

At 84, we can't be too sad at his passing. Instead, we can celebrate his pioneering ideas.

Categories: unix, programming

Dennis Ritchie

12:11 Sun, 16 Oct 2011

Sad to read today that Dennis Ritchie died a few days ago. His death did not make the popular press, unlike Steve Jobs', and, in a way, that is an indicator of his life. He was the archetypal quiet achiever.

Ritchie was the co-author of the C programming language and the UNIX operating system. Both were hugely influential on the development of almost every computing device we use today.

Ritchie had a great influence on me. I had bought my first real computer, an Amiga 1000 (after having a System-80, the local equivalent of the TRS-80), and it was written in C. I knew nothing about C and set out to learn. The first book I bought was K&R (otherwise known as The C Programming Language), and the rest is history.

The Guardian has two nice articles, a eulogy, and a good historical piece.

Categories: programming, unix

Vim Abbreviations for HTML

11:54 Mon, 01 Aug 2011

Vim abbreviations for HTML, including how to use the < character as a valid abbreviation.


I use Vim's abbreviations a lot when I write this blog. I have abbreviations for most of the common HTML tags and, for HTML, I use abbreviations that start with < so that they don't get mixed up with any other abbreviations.

A quick refresher: vim lets you assign a string to a keystroke sequence, much like an auto-correct feature. I can assign "Nick Coleman" to NC and whenever I type NC{space} vim will change that to Nick Coleman. (You don't have to type space, you can actually type any delimiter character such as Tab or Esc.)

Back to abbreviations for HTML, an example: insert a <p> tag:

iabbrev <buffer> <p <p>

I just type <p{space} and vim expands it to the full tag. I only save one keystroke

Categories: programming

Sudo Vim

23:12 Fri, 29 Jul 2011

Say you are editing in Vim and you need to edit a file owned by root. I have been using the sudo.vim plugin by Rich Paul, which lets you use sudo within Vim. It works fine, but here's a very simple alternative if you don't want to install a plugin just for this.

cmap w!! w !sudo tee % >/dev/null

Thanks to Hacker News user drtse4, who gave this incredibly useful tip.

(It needs tee, which most unix systems have installed or easily available as a package.)

Categories: unix, programming

A Script to Download Webcam Images

08:46 Tue, 21 Jun 2011

Using a script to pull webcam images; the script uses a file with a list of URLs, the time to pull the images, and any conversions needed when the URL is time or date specific.

I wrote previously about setting up an iMac G4 to display photos and images. The images are from webcams around the world, pulled every few hours and displayed automatically. Now I go into some details about how I do that. (You can download the script at the bottom of this page.

What factors do you need to take into account when getting a webcam image? You need a URL. You might decide you want to get the image only during daylight, so you need some method of telling the script whether to download the image on this run or not. Some webcam URLs have a date or time embedded in them, so you need some way of generating that URL or of picking the latest image. You might want to display a caption with the image. Finally, you want to be able to rename the image since you could find name collisions (e.g. many websites use "webcam.jpg"), so you want to specify a name for the image.


Categories: programming, unix, image

Timezone Converter

10:36 Sun, 05 Jun 2011

A very handy utility to convert time from one timezone to another.

It's funny how you start off doing one thing only to realise that, before you do that thing, you need to do another thing first, only to realise that before you do that, you need another thing first...

So it was with my webcam downloader script, which I was going to write about, then realised I needed to do another thing first. (I will write about the webcam script later, mes amis.)

One of the things you soon realise when you capture webcam images from around the world is that you need some method of getting the image only during certain times. For example, the Grand Canyon is nice, but not at night when the webcam shows pitch black. Then you realise you need a tool to convert Grand Canyon time to your local time so you can easily instruct your download script whether to get the image on this run or to leave it for a later run. In this example of the Grand Canyon, I only want to grab the image if it is between 7am to 6pm their time and so I need to convert those two times to my local time to test if I should retrieve them or not.

It is easy enough to manually convert one or two times to your local time using, say,

Categories: programming, unix

Const in C

17:58 Wed, 18 May 2011

If you can never remember where to place const in C, I read a handy tip recently.

Const always applies to the type to the left, the prefixed type. That's it. Except, if const is the first keyword then it applies to the following type. That's not really a cause of confusion though, because then it reads naturally.

Thus, these are all valid C:

const int a // const is first keyword int const a // prefixed int is const1 int *const ap // prefixed pointer, not the int, is const int const *const ap // both const const int *const ap // both const

The obvious gotcha is when using it with pointers and inadvertently applying it to the type instead of the pointer. So int const *ap; mean that the int is constant because the int type appears as a prefix to

Categories: programming