Lookup

Most of my writing inside the browser is done with the combination of the It’s All Text extension and Vim. During this writing, I use words whose meaning I know vaguely but don’t know the exact usage, and in such cases, I usually open a new browser window and look up the meaning of the word in an online dictionary. This process of looking up the dictionary meaning was getting rather tedious, so I wrote a small Vim plugin today to do this job with a simple command.

To use the plugin, first install BeautifulSoup. Then, get my lookup.vim script and copy it to ~/.vim/plugin/.. See the new version’s installation instructions, it now uses John Goerzen’s dict client implementation in Python.

Next time you use Vim, just place your cursor over any word and run :Lookup, and you’ll see something like this:

lookup.vim screenshot

Since, this is the only command starting with L on my Vim installation, I just end up running :L. Of course, you can always create your own keyboard shortcuts to make it easier.

Update: Based on the comments, I’ve updated the script to now use the DICT protocol and talks to some servers. This avoids screen-scraping, is much faster to use, allows me to now use both a dictionary and a thesaurus which is very very handy because I can see what other words I can use, and of course, doesn’t violate any TOS (which screen-scraping could amount to).

10 Responses to “Lookup”

  1. Sridhar Ratnakumar Says:

    By using wordnet, you can obviate internet connection and html scraping, http://nearfar.org/code/greclusters/dict.py

  2. Abhijit Nadgouda Says:

    Good one, trying it out.

  3. Michael Watkins Says:

    And, if your client is *nix, you can ignore wordnet and all and simply use dict at the command line. In vim:

    function! LookupDictionary() let theword = expand(”") exec ‘:!dict ‘ . theword endfunction

    ” Look up a word using dict nnoremap :call LookupDictionary() inoremap :call LookupDictionary()

  4. Just another WordPress weblog Says:

    [...] Swaroop C H, The Dreamer » Python: Lookup [...]

  5. Kartik Mistry Says:

    Cool. I will love to write similar plugin for GujaratiLexicon.com.

  6. Chris Says:

    This comment has just been written with “It’s All Text” and gvim, thanks for mentioning the former. :-)

  7. Swaroop Says:

    @Sridhar: Thanks, didn’t know about that.

    @Michael: Nice idea, although I tend to be on Windows too. Perhaps, there are binaries for dict on gnuwin32.sf.net

    @Kartik: Should be easy :)

    @Abhijit, @Chris: Enjoy!

  8. finferflu Says:

    Hi, I’ve just donwloaded your cool plugin, but I was unable to lookup words. Then I found out that the server indicated in the code is currently not working, so I have edited it to dict.org, and I also had to change moby-thesaurus to moby-thes, this way (I hope BBCode is on):

    
    conn = dictclient.Connection('dict.org')

    output += "\n".join([d.getdefstr() for d in conn.define('wn', word)]) # WordNet output += "\n\n" output += "\n".join([d.getdefstr() for d in conn.define('moby-thes', word)]) # Moby Thesaurus

    It would be nice if you could update the plugin on the Vim website :)

  9. Swaroop Says:

    @finferflu : Thanks for pointing that out, and I’ve updated the plugin on the vim website :)

  10. finferflu Says:

    Cool, thank you for your work :)

Leave a Reply


Policy on Comments : All comments will be moderated. Any off-topic comments will be deleted without notice.