sponsor Vim development Vim logo Vim Book Ad

vim-DetectSpellLang : guess the spell-check language of the current buffer

 script karma  Rating 0/0, Downloaded by 168  Comments, bugs, improvements  Vim wiki

created by
Enno Nagel
 
script type
utility
 
description
This plug-in makes Vim autodetect the tongue (= `&spelllang`) of the text
contained in a buffer (which is spell checked, that is, `&spell` is set).

It depends on the spell checker `aspell` (which is contained in many Linux
distributions by default, and also available for Microsoft Windows where
the path to its executable must be added to the `%PATH%` environment
variable).

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).

===========================================================================
2. Config

- The language is detected in-between those listed in the variable
  `g:guesslang_langs`. It is *empty* by default and has to be set by the user
  among those listed in the output of the command aspell dicts! For example,


  let g:guesslang_langs = [ 'en_US', 'de_DE', 'es', 'it' ]


- The value of 'g:guesslang_lines' defines how many lines are tested for
  spelling mistakes by aspell to derive the suitable spellcheck-language.
  By default


  let g:guesslang_lines = 20


- The values in the dictionary 'g:guesslang_ftoptions' define filetype-
  dependent options for aspell (to specify the filter mode, for example).
  By default


  let g:guesslang_ftoptions = {
    \ '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',
    \}


- The value of 'g:guesslang_threshold' defines the percentage of spelling
  mistakes among all words below which a spellcheck-language is recognized as
  correct. For example, with the default


  let g:guesslang_threshold' = 20


  and g:guesslang_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 GuessLangUpdate


  provides by the buffer-local variables b:guesslang_old and
  b:guesslang_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.

==

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.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vim-DetectSpellLang.zip 1.1 2019-07-10 7.0 Enno Nagel add configuration options and fix tidbits
vim-guesslang.zip 1.0 2016-11-27 7.4 Enno Nagel Initial upload
ip used for rating: 35.171.183.163

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
OSDN.net Logo