Home

Awesome

Multi-Language Thesaurus Query/Replacement Plugin

Join the chat at https://gitter.im/Ron89/thesaurus_query.vim

This is a plugin for user to lookup synonyms of any word under cursor or phrase covered in visual mode, and replace it with an user chosen synonym. It also accepts word/phrases from manual input for synonym checkup.

Notice: Currently this plugin Supports only English (en), Chinese (cn), French (fr), Russian (ru) and German (de) thesaurus query. If you want to use the plugin for other languages, or if you're not satisfied with the performance of current backends and know of some online synonym services that I can integrate into the plugin, please come and post an issue with your suggestion.

This plugin is written in Python. So +Python or +Python3 version of Vim is required.

What's new

Deleted thesaurus_com backend due to the legal warning from Thesaurus.com on the upstream package thesarus. For existing users that still have thesaurus_com explicitly enabled, the backend now always return exception. For English users, currently the highest quality source is either the OpenOffice Thesaurus source or mthesaur.txt. I am sorry for any inconvenience caused.


Added two new French backend based on synonymo.fr and cnrtl.fr. To activate them, add fr to variable g:tq_language and synonymo_fr and/or cnrtl_fr to g:tq_enabled_backends.


Added new German backend based on openthesaurus.de. This thesaurus backend is one of the German default backends. To activate it, add de to variable g:tq_language. Also, if you have manual specification for g:tq_enabled_backends, be sure to add openthesaurus_de to your backend list.


Added new Russian backend based on yarn-synsets.csv. To use, add yarn_synsets to Vim variable g:tq_enabled_backends, e.g.

let g:tq_enabled_backends=["yarn_synsets", "openoffice_en", "mthesaur_txt"]

also, add ru to variable g:tq_language and make sure that either yarn-synsets.csv in downloaded to ~/.vim/thesaurus or where variable g:tq_yarn_synsets_file points at.


A new variable is designed to force use certain version of Python, e.g.

let g:tq_python_version = 2

will force Plugin to use Python2 no matter if Python3 is supported.

Installation

Use your plugin manager of choice.

Usage

By default, command :ThesaurusQueryReplaceCurrentWord is mapped to <Leader>cs.

nnoremap <Leader>cs :ThesaurusQueryReplaceCurrentWord<CR>

This routine check the synonyms of the word under cursor and replace it with the candidate chosen by user. The corresponding non-replacing routine is defined as ThesaurusQueryLookupCurrentWord. User may choose to use it if you prefer the split buffer display of result over the word replacement routine.


Another might-be-useful routine is the one to query synonym for and replace a multi-word phrase covered in visual mode, using the same key mapping <Leader>cs

vnoremap <Leader>cs y:ThesaurusQueryReplace <C-r>"<CR>

The phrase covered in visual mode can be in a same line, or wrapped in two or more lines.


Also, this plugin support Vim's builtin completefunc insert mode autocomplete function. To invoke it, use keybinding ctrl-x ctrl-u in insert mode. This function resembles Vim's own thesaurus checking function, but using online resources for matchings.


Finally, this plugin support thesaurus checkup for manually input through command mode command :Thesaurus.

:Thesaurus your phrase

Configuration

Description for backends and their setup

To ensure stability of the plugin's functionality, under the hood, this plugin uses multiple backends sequentially to query for a synonym. Backends function independently, hence the plugin will be functional as long as one of the these backends is behaving properly.

The thesaurus query plugin will go through the list g:tq_enabled_backends in sequence until a match is found. Unless user explicitly instruct, Next query will be conducted only when the previous query return empty synonym list or failed to query. You may remove unwanted backend or lower their priority by removing them/putting them on latter position in variable g:tq_enabled_backends as following example:

let g:tq_enabled_backends=["woxikon_de","jeck_ru","openoffice_en","mthesaur_txt"]
let g:tq_enabled_backends=["cilin_txt",
            \"openthesaurus_de",
            \"yarn_synsets",
            \"openoffice_en",
            \"mthesaur_txt",
            \"datamuse_com",]

Non-Engligh backends are currently not activated by default, due to the default setting g:tq_language='en'. To enable Russian, German, or Chinese backend, add 'ru', 'de' or 'cn' to the tq_language list:

let g:tq_language=['en', 'ru', 'de', 'cn']

Or if you want to use only German thesaurus engine in specific/current buffer

let b:tq_language=['de']

To ensure the best user experience, the backend that reports error during query will have its priority automatically lowered. If user want to restore originally defined priority, simply invoke command

:ThesaurusQueryReset

Online Backends Timeout Mechanism

Timeout mechanism (configurable with g:tq_online_backends_timeout) is added to all online query backends to reduce query time(in seconds). Default value is 1.0 (second), so that user using slower internet or having long response time with certain backend servers could still has reliable performance. For users with faster internet, you may want to lower the value (mine is 0.4).

let g:tq_online_backends_timeout = 0.4

Q: Why would this help?

A: Usually when thesaurus is found, the server respond quickly. However, when the word is not found, it will take a while before server return 404 error. And our plugin will freeze Vim before the error is returned. By setting timeout, we may cut the waiting time down and start query from next backend sooner. So that waiting-time for user can be drastically reduced if set properly.

Q: What does it mean by long response time to certain servers

A: Depending on where you are, some thesaurus query service might not have server built up close to you. In this case, the response time between you and the server might varied greatly. For example, woxikon_de might only have server in Germany. And I am in Singapore. Based on my experience, it might take 400ms-1.0s for the server to respond to my request. If I want to use its service reliably, I might want to set the timeout to 1.0 (second), so that most of the valid query can yield response before timeout.

Truncate query result in candidate window

Synonym replacing interface(shown in first screenshot) is the key feature of this plugin. I will make my best effort to make sure it work sensibly. If user has any complain about the current layout or otherwise, please draft an issue to let me know. Currently, I have drafted two variables to help reducing the candidate list when the number of synonym is too overwhelming.

Synonym group truncate

Synonyms are grouped by definitions. If there are too many groups to your liking, you may reduce the number of groups shown to 3 by setting

let g:tq_truncation_on_definition_num = 3

Synonym list truncate

Sometimes synonyms in a single group is also too long to choose from, in this case, to reduce the number of synonym shown in each group to no more than 200, you can set

let g:tq_truncation_on_syno_list_size = 200

Know that if query result is truncated by your rule, and you want to browse through the result being truncated, you can still access the complete synonym list by typing A<Enter> in your input prompt.

Notice Due to current lack of user feedback, and that I do not want to arbitrarily make up truncation threshold that may damage user experience, both truncation methods are inactive unless variables stated above are set explicitly by user.

Credit

This plugin is functionally based on and extended from the idea behind vim-online-thesaurus by Anton Beloglazov:

Several key improvements were made comparing to his plugin:

TODO List

  1. Add more thesaurus source and try to parallelize the query process with a timeout limit.
  2. Implement algorithm to make synonym candidates in a same form(tense, plurality, etc.). This could take a while... :-|
  3. Update documentation