≡ Menu

Vi and Vim Editor: 3 Steps To Enable Thesaurus Option

Vi or Vim Thesaurus
Photo courtesy of dantesz

This is a guest post written by SathiyaMoorthy.

Enabling thesaurus option for vi / vim will help you to choose alternate words from thesaurus. For example, while typing “important”, you may prefer to use a different word than “important”.  Wouldn’t be nice if vi can give you few alternative words such as: “valuable” or “substantial” or “significant”?

This article explains how to use vi / vim effectively by enabling thesaurus option in three steps.

Step 1: Define a Thesaurus file

All the relevant words should be grouped together on a single line with either comma or space delimited. For example, you can create your own thesaurus file as shown below for the word “important”.

$ vim /home/jsmith/mythesaurus.txt

Step 2: Specify Thesaurus File Location in ~/.vimrc

Add the following line to .vimrc specifying the location of thesaurus file.

$ vim ~/.vimrc
set thesaurus+=/home/jsmith/mythesaurus.txt

Step 3: Use Thesaurus While Editing Document Using Ctrl x + Ctrl t

From vim, if you want to use an alternative word, press Ctrl x + Ctrl t in the insert mode. For example, when you’ve typed the word “important”, press Ctrl-x and Ctrl-t, which will show a popup with the alternate words “valuable”, “substantial” and “significant” as shown below from your /home/jsmith/mythesaurus.txt file.

Vi Vim Thesaurus Option
Fig: Launch Thesaurus from vi using Ctrl x and Ctrl t

Download and Use a Pre-defined Thesaurus

Instead of defining your own custom thesaurus, download and use the pre-defined famous moby thesaurus as shown below.

$ wget http://www.gutenberg.org/dirs/etext02/mthes10.zip

$ unzip mthes10.zip
Archive:  mthes10.zip
inflating: aaREADME.txt
inflating: roget13a.txt
inflating: mthesaur.txt

Use mthesaur.txt as the thesaurus file. It is quite large and you would get more than 50 related words for each word.

Add the following line to .vimrc to specify the location of the mthesaur.txt thesaurus file.

$ vim ~/.vimrc
set thesaurus+=/home/jsmith/mthesaur.txt

How can a programmer use thesaurus feature in vim?

This can be very helpful for programmers. For example, a PHP programmer can create a php-functions file with the following lines and specify this as thesaurus file inside the ~/.vimrc.

$ vim /home/jsmith/php-functions.txt
math abs acos acosh asin asinh atan atan2 atanh base_convert bindec ceil cos
errors debug_backtrace debug_print_backtrace error_get_last error_log error_reporting restore_error_handler

Add the php-functions.txt to .vimrc specifying the location of thesaurus file.

$ vim ~/.vimrc
set thesaurus+=/home/jsmith/mythesaurus.txt
set thesaurus+=/home/jsmith/mthesaur.txt.txt
set thesaurus+=/home/jsmith/php-functions.txt

Now, when you type “math” in your PHP file and press Ctrl x and Ctrl t, all the PHP math functions will be displayed. Also, please note that you define multiple thesaurus files as shown above.

Recommended Reading

Learning the Vi and Vim Editors, by Arnold Robbins. I’m a command-line junkie. So, naturally I’m a huge fan of Vi and Vim editors. Several years back, when I wrote lot of C code on Linux, I used to carry the Vi editor pocket reference with me all the times. Even if you’ve been using Vi and Vim Editors for several years and have not read this book, please do yourself a favor and read this book. You’ll be amazed with the capabilities of Vim editor.


This article is part of the ongoing Vi Tips and Tricks series. Please subscribe to TheGeekStuff and don’t miss any future Vi and Vim editor tips and tricks.

This article was written by SathiyaMoorthy, developer of EPQA. Sathiya got impressed by the 15 Examples To Master Linux Command Line History article on this blog and became a regular reader and contributor. The Geek Stuff welcomes your tips and guest articles.

Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Lakshmanan December 16, 2008, 11:43 pm


  • mk_michael December 17, 2008, 9:24 am

    Amazing stuff 😉 But I’m not really sure in wich case I can use this feature, but great!

  • SathiyaMoorthy April 1, 2009, 11:26 am


    Thanks for your comment & appreciation.

    The theme of this article is to publish about the two practical usages, one is for a programmer and other is for every body.
    1. Programmer can use it for, navigating through the relevant function names using ctrl x + ctrl t.
    2. Non programmer can use it for, while editing the document, mail and other text related stuffs and use newer English words in it.

    If you have some other practical usages let us know about it.

  • Gilles April 8, 2009, 5:54 am

    Great tip. I really like your website: you take te time to explain and to illustrate the tips 🙂 Thanks for the time that you spend on these tasks 🙂

  • Ramesh April 10, 2009, 5:30 pm


    Thanks for the very nice compliment about The Geek Stuff website. We try hard to deliver high-quality articles on an on-going basis. We are always very happy and excited to read these nice compliments.

  • Nick December 27, 2009, 10:46 pm

    Nice tip, thanks for the link to a thesaurus.

    Using 7.2, I get a “tag stack empty” error when I try to use it with C-x, C-t. I’m reluctant to go and create a huge tags file given the size of mthesaur.txt and that I’ll only be using for text files, which is only a small number of times compared to doing programming. I don’t want that 10M of tags memory being used when I’m writing python code.

    Anything else I should have done to get this working?

  • Anonymous February 19, 2010, 10:02 am

    Nick– you need to be in insert mode.

  • Aquino August 15, 2010, 7:38 am

    An alternative is to use this plugin:

    To enable the plugin on Debian/Ubuntu:
    sudo aptitude install python-nltk openoffice.org-thesaurus-en-us

  • Pablo February 26, 2011, 11:17 am

    The tip on how to use the moby thesaurus in vi was excellent!
    Is there a way to also implement an English dictionary? I find myself using vi more and more for all sorts of editing tasks, and with a dictionary (and thesaurus) implemented, I could easily give up stardict (and all its dependencies) and use vi from console for all my writing/editing needs.
    Many thanks !! 🙂

  • Russ Urquhart May 15, 2014, 9:39 am


    I tried this and i get a pattern not found after trying the ctrl-x ctrl-t. Any ideas?

  • Alexandre June 3, 2014, 2:42 am

    I did the steps in the tutorial but I have like 10000+ matches for the word important?? do you know why?