vim-DetectSpellLang : autodetect the spell-check language of the current buffer
script karma |
Rating 0/2,
Downloaded by 1294 |
Comments, bugs, improvements
|
Vim wiki
|
created by |
Enno Nagel |
|
script type |
utility |
|
description |
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).
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 from
http://www.rapidee.com), or
- set by g:detectspelllang_program, say
let g:detectspelllang_program = 'C:\Program Files (x86)\Aspell\bin\aspell.exe'
===========================================================================
INITIAL 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, for example 'text',
'markdown' and 'mail', are spell checked, add either the line
autocmd FileType text,markdown,mail setlocal spell
or the line
setlocal spell
to ~/.vim/ftplugin/text.vim (respectively markdown.vim and mail.vim).
The language is detected, depending on whether aspell respectively hunspell
is used, among those listed in g:detectspelllang_langs.aspell respectively
g: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, in case you use aspell,
let g:detectspelllang_langs = {}
let g:detectspelllang_langs.aspell = [ 'en_US', 'de_DE', 'es', 'it' ]
respectively, in case you use hunspell,
let g:detectspelllang_langs.hunspell = [ 'en_US', 'de_DE', 'es_ES', 'it_IT' ]
===========================================================================
CONFIGURATION
===========================================================================
- The value of 'g:detectspelllang_lines' defines how many lines are tested for
spelling mistakes by hunspell to derive the suitable spellcheck-language.
By default
let g:detectspelllang_lines = 1000
- The values in the dictionary 'g:detectspelllang_ftoptions' define filetype-
dependent options for aspell respectively hunspell (to specify the filter mode, for example).
By default
let 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'],
\}
and
let g:detectspelllang_ftoptions.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_threshold' defines the percentage of spelling
mistakes among all words below which a spellcheck-language is recognized as
correct. For example, if
let g:detectspelllang_threshold = 20
and g:detectspelllang_langs.aspell = [ 'en_US', 'de_DE' ] and 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.
===========================================================================
ISSUES
===========================================================================
This plug-in vim-DetectSpellLang is developed at
https://github.com/konfekt/vim-DetectSpellLang where issues can be filed.
|
|
install details |
Unzip vim-guesslang.zip into ~/.vim on Linux (or MacOS) respectively %USERPROFILE%\vimfiles on Windows. |
|
script versions (upload new version)
Click on the package to download.
ip used for rating: 3.239.76.211
|