VIM同义词库文件
我一直在寻找vim同义词表的好解决方案。显然,该功能是内置的,但每个人似乎都使用的文件是mthesaur.txt。虽然它在插入模式下的命令会显示一个列表的意义上“起作用”,但在我看来,结果在编程上是正确的,但并不是非常有用。vim online thesaurus插件工作得很好,但在线延迟和对返回的缓冲区使用拆分的必要性并不理想。有人对此有意见吗?我写了一个插件,可以解决您在这里提出的两个问题 它在两个方面改进了使用体验:更明智的同义词选择 机制;以及更好、更灵活的同义词源 默认情况下,插件使用vim的messagebox显示候选项,每个选项 用数字标记的同义词。并让用户选择合适的替代品 通过键入光标下的单词的数字,可以将其置于光标下。它的工作原理与vim的类似 默认拼写更正提示。大大缩短了设备的运行时间 从一长串候选词中选择合适的同义词 为了提高同义词候选词的质量,使用了多个查询后端 用过。对于英语用户来说,有两个是值得注意的VIM同义词库文件,vim,thesaurus,Vim,Thesaurus,我一直在寻找vim同义词表的好解决方案。显然,该功能是内置的,但每个人似乎都使用的文件是mthesaur.txt。虽然它在插入模式下的命令会显示一个列表的意义上“起作用”,但在我看来,结果在编程上是正确的,但并不是非常有用。vim online thesaurus插件工作得很好,但在线延迟和对返回的缓冲区使用拆分的必要性并不理想。有人对此有意见吗?我写了一个插件,可以解决您在这里提出的两个问题 它在两个方面改进了使用体验:更明智的同义词选择 机制;以及更好、更灵活的同义词源 默认情况下,插件
后台使用thesaurus.com作为同义词源thesaurus\u com
后台使用mthesaur.txt作为同义词源mthesaur\u txt
thesaurus\u com
后端将立即工作。要使本地查询后端正常工作,
您需要下载mthesaur.txt
并告诉插件它在哪里
通过设置变量同义词库或指定
变量g:tq\u mthesaur\u文件
。否则,将只使用在线后端
功能性的
默认情况下,将首先使用联机查询后端。但如果互联网不是
可用或太慢,将处理当前vim会话中的未来查询
首先通过本地查询后端来减少延迟时间。这两者的优先次序
后端也可以手动更改(请参阅)
为了解决延迟问题(通常在找不到单词时会突出),我引入了超时机制。你可以设定
let g:tq_online_backends_timeout = 0.6
如果你的网速相当快。这样就可以将延迟时间减少到
在0.6秒以下
不过,该插件是用Python编写的。因此,您可能希望将其与使用Python和/或Python3支持编译的Vim一起使用。如果您的系统类似于unix,并且安装了awk,那么我有一个
您的问题的简单解决方案,使您能够访问
无internet连接且无拆分的多种语言
窗户也可以
首先从以下位置下载LibreOffice同义词表:
比如说
(注意th_*.dat文件,这些是您需要的文件,而不是.aff和
.dic文件,仅用于拼写检查。)下载
把你喜欢的*.dat同义词表复制到
文件夹,你将把你的插件;这个子目录应该是
叫“thes”
现在在你的插件文件夹中创建一个新文件(你应该
将带有*.dat同义词表的“thes”子目录放入
此文件中包含以下内容:
" offer choice among installed thesauri
" ==================================================
let s:thesaurusPath = expand("<sfile>:p:h") . "/thes"
function! s:PickThesaurus()
" 1, 1: glob does not ignore any pattern, returns a list
let thesaurusList = glob(s:thesaurusPath . "/*", 1, 1)
if len(thesaurusList) == 0
echo "Nothing found in " . s:thesaurusPath
return
endif
let index = 0
let optionList = []
for name in thesaurusList
let index = index + 1
let shortName = fnamemodify(name, ":t:r")
let optionList += [index . ". " . shortName]
endfor
let choice = inputlist(["Select thesaurus:"] + optionList)
let indexFromZero = choice - 1
if (indexFromZero >= 0) && (indexFromZero < len(thesaurusList))
let b:thesaurus = thesaurusList[indexFromZero]
endif
endfunction
command! Thesaurus call s:PickThesaurus()
这将允许您获取在insert中键入的任何单词的同义词
模式仍处于插入模式时,按Ctrl-X Ctrl-O(或任意键
您在omnicompletion上映射的组合)和弹出菜单将显示
使用同义词列表
与Chong强大的插件(见上文)相比,这个解决方案非常粗糙,但它很轻,对我来说足够好。我将它与四种不同语言的同义词库一起使用。脚本对于~/.vimrc,它需要路径中的文件thesaurii.txt(来自的合并词典)和perl.exe来搜索同义词。在win7和cygwin perl上测试的脚本
如果找不到同义词,则调用aspell进行拼写更正。请参见如何在按[tab]时调用此函数
set thesaurus=thesaurii.txt
let s:thesaurus_pat = "thesaurii.txt"
set completeopt+=menuone
set omnifunc=MoshThesaurusOmniCompleter
function! MoshThesaurusOmniCompleter(findstart, base)
" == First call: find-space-backwards, see :help omnifunc
if a:findstart
let s:line = getline('.')
let s:wordStart = col('.') - 1
" Check backward, accepting only non-white space
while s:wordStart > 0 && s:line[s:wordStart - 1] =~ '\S'
let s:wordStart -= 1
endwhile
return s:wordStart
else
" == Second call: perl grep thesaurus for word_before_cursor, output: comma separated wordlist
" == Test: so % and altitude[press <C-x><C-o>]
let a:word_before_cursor = substitute(a:base,'\W','.','g')
let s:cmd='perl -ne ''chomp; '
\.'next if m/^[;#]/;'
\.'print qq/$_,/ if '
\.'/\b'.a:word_before_cursor.'\b/io; '' '
\.s:thesaurus_pat
" == To: Debug perl grep cmd, redir to file and echom till redir END.
" redir >> c:/tmp/vim.log
" echom s:cmd
let s:rawOutput = substitute(system(s:cmd), '\n\+$', '', '')
" echom s:rawOutput
let s:listing = split(s:rawOutput, ',')
" echom join(s:listing,',')
" redir END
if len(s:listing) > 0
return s:listing
endif
" Try spell correction with aspell: echo mispeltword | aspell -a
let s:cmd2 ='echo '.a:word_before_cursor
\.'|aspell -a'
\.'|perl -lne ''chomp; next unless s/^[&]\s.*?:\s*//; print '' '
let s:rawOutput2 = substitute(system(s:cmd2), '\n\+$', '', '')
let s:listing2 = split(s:rawOutput2, ',\s*')
if len(s:listing2) > 0
return s:listing2
endif
" Search dictionary without word delimiters.
let s:cmd3='perl -ne ''chomp; '
\.'next if m/^[;#]/;'
\.'print qq/$_,/ if '
\.'/'.a:word_before_cursor.'/io; '' '
\.&dictionary
let s:rawOutput3 = substitute(system(s:cmd3), '\n\+$', '', '')
let s:listing3 = split(s:rawOutput3, ',\s*')
if len(s:listing3) > 0
return s:listing3
endif
" Don't return empty list
return [a:word_before_cursor, '(no synonyms or spell correction)']
endif
endfunction
set thesaurus=thesaurii.txt
让我们看一下:thesaurus_pat=“thesaurii.txt”
set completeopt+=menuone
set omnifunc=MoshThesaurusOmniCompleter
功能!莫什塔鲁斯奥姆尼完成器(findstart,base)
==第一次调用:向后查找空间,请参阅:help omnifunc
如果a:findstart
让s:line=getline('.'))
设s:wordStart=col('.')-1
向后检查,只接受非空白
而s:wordStart>0&&s:line[s:wordStart-1]=~'\s'
让我们:wordStart-=1
循环结束
返回s:wordStart
其他的
==第二次调用:perl grep同义词库,用于单词\u光标前的\u,输出:逗号分隔的单词列表
“==测试:so%和高度[按]
让a:word\u在\u游标之前=替换(a:base,“\W”,“g”)
让我们:cmd='perl-ne''chomp;'
\.“下一个如果m/^[#]/;”
\.“打印qq/$\u,/if”
\'/\b'.a:光标前的单词'.'\b/io;''
\.s:同义词表
==To:Debug perl grep cmd,redir To file和echom直到redir结束。
“redir>>c:/tmp/vim.log
“echom s:cmd
设s:rawOutput=substitute(系统(s:cmd),“\n\+$”,“,”)
“echom s:rawOutput
让s:listing=split(s:rawOutput,,)
“echom连接(s:列表,”,“)
“重拨结束
如果len(s:listing)>0
返回s:列表
恩迪夫
“尝试使用aspell:echo mispeltword | aspell-a更正拼写
让s:cmd2='echo'.a:word\u在\u光标之前
\“阿斯佩尔-a”
\“| perl-lne”chomp;next除非s/^[&]\s.*?:\s*/;print''
让s:rawOutput2=替换(系统(s:cmd2),“\n\+$”,“,”)
设s:listing2=split(s:rawOutput2,“,\s*”)
如果len(s:listing2)>0
返回s:listing2
恩迪夫
“搜索不带单词分隔符的词典。
让我们:cmd3='perl-ne''chomp;'
\.“下一个如果m/^[#]/;”
\.“打印qq/$\u,/if”
set thesaurus=thesaurii.txt
let s:thesaurus_pat = "thesaurii.txt"
set completeopt+=menuone
set omnifunc=MoshThesaurusOmniCompleter
function! MoshThesaurusOmniCompleter(findstart, base)
" == First call: find-space-backwards, see :help omnifunc
if a:findstart
let s:line = getline('.')
let s:wordStart = col('.') - 1
" Check backward, accepting only non-white space
while s:wordStart > 0 && s:line[s:wordStart - 1] =~ '\S'
let s:wordStart -= 1
endwhile
return s:wordStart
else
" == Second call: perl grep thesaurus for word_before_cursor, output: comma separated wordlist
" == Test: so % and altitude[press <C-x><C-o>]
let a:word_before_cursor = substitute(a:base,'\W','.','g')
let s:cmd='perl -ne ''chomp; '
\.'next if m/^[;#]/;'
\.'print qq/$_,/ if '
\.'/\b'.a:word_before_cursor.'\b/io; '' '
\.s:thesaurus_pat
" == To: Debug perl grep cmd, redir to file and echom till redir END.
" redir >> c:/tmp/vim.log
" echom s:cmd
let s:rawOutput = substitute(system(s:cmd), '\n\+$', '', '')
" echom s:rawOutput
let s:listing = split(s:rawOutput, ',')
" echom join(s:listing,',')
" redir END
if len(s:listing) > 0
return s:listing
endif
" Try spell correction with aspell: echo mispeltword | aspell -a
let s:cmd2 ='echo '.a:word_before_cursor
\.'|aspell -a'
\.'|perl -lne ''chomp; next unless s/^[&]\s.*?:\s*//; print '' '
let s:rawOutput2 = substitute(system(s:cmd2), '\n\+$', '', '')
let s:listing2 = split(s:rawOutput2, ',\s*')
if len(s:listing2) > 0
return s:listing2
endif
" Search dictionary without word delimiters.
let s:cmd3='perl -ne ''chomp; '
\.'next if m/^[;#]/;'
\.'print qq/$_,/ if '
\.'/'.a:word_before_cursor.'/io; '' '
\.&dictionary
let s:rawOutput3 = substitute(system(s:cmd3), '\n\+$', '', '')
let s:listing3 = split(s:rawOutput3, ',\s*')
if len(s:listing3) > 0
return s:listing3
endif
" Don't return empty list
return [a:word_before_cursor, '(no synonyms or spell correction)']
endif
endfunction