Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is vim able to detect the natural language of a file, then load the correct dictionary?

I am using several languages, and currently I am obliged to indicate to vim with which of these the spell check must be done. Is there a way to set up vim so that it automatically detects the correct one? I vaguely remember that in a previous version of vim, when the spell check was not integrated, the vimspell script made this possible.

It would be even better if this could apply not only to a file but also to a portion of a file, since I frequently mix several languages in a single file. Of course, I would like to avoid to load several dictionaries simultaneously.

like image 686
Niels Avatar asked Mar 28 '10 08:03

Niels


2 Answers

I don't know if there is a way to autodetect it, but if you put vim:spell:spelllang=foo,bar,baz at the bottom of the file, vim will set the spellchecking languages to foo, bar, and baz when the file is opened. Note that you must put at least one space before that text, or vim will think it's part of the file.

like image 88
m42a Avatar answered Oct 26 '22 05:10

m42a


Since vim is missing this feature, I found it useful to define shortcuts like these in .vimrc:

command! Nb :set spelllang=nb
command! En :set spelllang=en
like image 45
knatten Avatar answered Oct 26 '22 04:10

knatten