Ⅰ. 插件描述
make Vim autodetect the spellcheck language of the opened bufferⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'konfekt/vim-detectspelllang'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'konfekt/vim-detectspelllang'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'konfekt/vim-detectspelllang'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/konfekt/vim-detectspelllang
Ⅳ. 文档说明
DetectSpellLang
Introduction
This Vim plug-in autodetects the tongue (= &spelllang) of the text in a buffer (if it is spell checked, that is, &spell is set, and &spelllang has not been explicitly set, say by a modeline :help modeline).
CHANGES
Version 2.0 introduces breaking changes.
Please adapt your configuration accordingly:
- Substitute the prefix
g:guesslang_byg:detectspelllang_, - Substitute the autocommand event label
GuessLangUpdatebyDetectSpellLangUpdate, and Substitute, say
let g:guesslang_langs = [ ... ]
by
let g:detectspelllang_langs = {}
let g:detectspelllang_langs.aspell = [ ... ]where `...` is your list of `g:guesslang_langs`.
Installation
It uses either the spell checker aspell or hunspell (which are installed in many Linux distributions, in Mac OS, and both available for Microsoft Windows.
In Microsoft Windows the path to the executable must
- be either added to the
%PATH%environment variable (say by Rapidee), or - set by
g:detectspelllang_program, say
let g:detectspelllang_program = 'C:\Program Files (x86)\Aspell\bin\aspell.exe'The Chocolatey package hunspell automatically adds hunspell to the %PATH.
Set-up
This plug-in only operates in buffers that are spell checked, that is, &l:spell is set.
To ensure that certain file types, such as text, markdown and mail, are spell checked, add either the line
autocmd FileType text,markdown,mail setlocal spellor the line
setlocal spellto text.vim, markdown.vim and mail.vim in ~/.vim/ftplugin (on Microsoft Windows, in %USERPROFILE%\vimfiles\ftplugin).
The executable of the spell checker is automatically detected and preference given to aspell.
You can override this automatic detection by adding to you vimrc say
let g:detectspelllang_program = 'hunspell'The language is detected, depending on whether aspell respectively hunspell
is used, among those listed in g:detectspelllang_langs.aspell respectivelyg:detectspelllang_langs.hunspell. It is empty by default and has to be
set by the user to a list of languages included in that of the output of the
command aspell dicts respectively hunspell -D!
For example,
let g:detectspelllang_langs = {
\ 'aspell' : [ 'en_US', 'de_DE', 'es', 'it' ],
\ 'hunspell' : [ 'en_US', 'de_DE', 'es_ES', 'it_IT' ],
\ }Please pay attention, as hunspell does, to the upper case of the suffix of the language code.
Configuration
The value of
g:detectspelllang_linesdefines how many lines are tested for spelling mistakes byaspellorhunspellto derive the suitable spellcheck-language.
By defaultlet g:detectspelllang_lines = 1000The values in the dictionary 'g:detectspelllang_ftoptions' define filetype dependent options for
aspellorhunspell(to specify the filter mode, for example).
By defaultlet g:detectspelllang_ftoptions = { \ 'aspell' : { \ 'tex' : ['--mode=tex', '--dont-tex-check-comments'], \ 'html' : ['--mode=html'], \ 'nroff' : ['--mode=nroff'], \ 'perl' : ['--mode=perl'], \ 'c' : ['--mode=ccpp'], \ 'cpp' : ['--mode=ccpp'], \ 'sgml' : ['--mode=sgml'], \ 'xml' : ['--mode=sgml'], \}, \ 'hunspell' : { \ 'tex' : ['-t'], \ 'html' : ['-H'], \ 'nroff' : ['-n'], \ 'odt' : ['-O'], \ 'xml' : ['-X'], \} \ }
Note that on Windows the most recent official aspell binaries are from
2002 and do not support all above file type options, for example, for 'tex'.
The value of
g:detectspelllang_thresholddefines the percentage of spelling mistakes among all words below which a spellcheck-language is recognized as correct.
For example, with the defaultlet g:detectspelllang_threshold = 20
and g:detectspelllang_langs = [ 'en_US', 'de_DE' ], if less than 20% of all words in the buffer are spelling mistakes for `'en_US'`, then `'DetectSpellLang'` does not verify if the percentage of spelling mistakes for `'de_DE'` is below that for `'en_US'`.
The autocommand event
User DetectSpellLangUpdate
provides by the buffer-local variables `b:detectspelllang_old` and `b:detectspelllang_new` the previous and current value of `&l:spelllang`, the spell-check language.
This way, a user command, for example for adding and removing abbreviations specific to a language, can hook in.
Credits
This plug-in fleshes out a gist by Arno Renevier that, later on, in May 2019, turns out to be part of a plug-in GuessLang.vim from 2011 by the same author.