I have been poking around for a good solution for a vim thesaurus. The capability is built-in, obviously, but the file everyone seems to use is the mthesaur.txt. While it 'works' in the sense that the commands in insert mode bring up a list, it seems to me the results are programatically correct but not super useful. The vim online thesaurus plugin works very well, but the latency over the wire and necessity of using a split for the returned buffer is less than ideal. Anyone have an opinion about this?
相关问题
- Emacs shell: save commit message
- How to change the first two uppercase characters o
- Insert text into current buffer from function
- Hot reload on save
- Substituting zero-width match in vim script
相关文章
- 如何让 vim 支持 .cshtml 文件的代码高亮
- Auto-save in VIM as you type
- How can I use gcc's -I command to add recursiv
- Vim: overloaded mapping for multiple modes
- How to use relative line numbering universally in
- How to copy the value of a vim option to a registe
- E185: Cannot find color scheme*
- How do I fix vim to properly indent folds containi
If your system is unix-like and if you have awk installed, then I have a simple solution to your problem that gives you access to thesauri in multiple languages without internet connection and without a split window either.
First download LibreOffice thesauri from:
https://cgit.freedesktop.org/libreoffice/dictionaries/tree/
for example.
(Look after th_*.dat files, these are the ones you need, not the .aff and .dic files which work only for spellchecking with Hunspell.) Download the *.dat thesauri of your liking and copy them to a subdirectory of the folder where you will put your plugin; this subdirectory should be called, "thes."
Now create a new file in your plugin folder (the folder where you should have the "thes" subdirectory with the *.dat thesauri inside) and put the following in this file:
This will allow you to pick the thesaurus of your choice by typing
:Thesaurus
in Vim's command mode.(Actually, if you plan to use only one thesaurus then you don't need any of this; just assign the full name of your thesaurus file to the buffer-local variable,
b:thesaurus
).Finally, add the following to your plugin file:
This will allow you to get the synonyms of any word you type in insert mode. While still in insert mode, press Ctrl-X Ctrl-O (or any key combination you mapped on omnicompletion) and a popup menu will show up with the synonym list.
This solution is very crude as compared to Chong's powerful plugin (see above), but it is lightweight and works well enough for me. I use it with thesauri in four different languages.
Script for ~/.vimrc, it needs the file thesaurii.txt (merged dictionaries from https://github.com/moshahmed/vim/blob/master/thesaurus/thesaurii.txt) and perl.exe in path for searching for synonyms. Script tested on win7 and cygwin perl.
Calls aspell to do spell correction, if no synonyms are found. See https://stackoverflow.com/a/53825144/476175 on how to call this function on pressing [tab].
I have written a plugin that can address the two issues you raised here.
Multi-language Thesaurus Query plugin for Vim
It improves the using experience in two regards: more sensible synonym choosing mechanism; and better and more flexible synonym source(s).
Thesaurus_query.vim screen cast
By default, the plugin uses vim's messagebox for candidate display, with each synonym labeled by a number. And it let user choose the suitable one to replace the word under cursor by typing in its number. It works similar to vim's default spell correction prompt. And drastically reduced the operation time for choosing proper synonym from a long list of candidates.
To improve the quality of synonym candidates, multiple query backends were used. For English user, two are note worthy.
thesaurus_com
Backend using Thesaurus.com as synonym sourcemthesaur_txt
Backend using mthesaur.txt as synonym sourcethesaurus_com
Backend will work straight away. For Local Query Backend to work, you will need to downloadmthesaur.txt
and tell the plugin where it is located either by setting variablethesaurus
or specifying variableg:tq_mthesaur_file
. Or else only Online Backend will be functional.By default, Online Query Backend will be used first. But if internet is not available or too slow, future query in the current vim session will be handled by Local Query Backend first to reduce latency time. Priority of these two backends can also be manually altered(see documentation).
To address the latency issue(which usually stands out when the word is not found), I have introduced a timeout mechanism. You may set
if your internet is reasonably fast. So that the latency could be reduced to under 0.6 second.
The plugin is written in Python, though. So you might want to use it with Vim compiled with Python and/or Python3 support.