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 important,valuable,substantial,significant
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.
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.
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.
Get the Linux Sysadmin Course Now!