Skip to content

Instantly share code, notes, and snippets.

@fmoralesc
Created October 15, 2010 20:52
Show Gist options
  • Save fmoralesc/628930 to your computer and use it in GitHub Desktop.
Save fmoralesc/628930 to your computer and use it in GitHub Desktop.
a vim script for detecting the language of a text file and setting the spelling language automatically.
if (exists("g:loaded_detect_lang") && g:detect_lang) || &cp
finish
endif
let g:detect_lang = 1
command! DetectLanguage exec('py detect_language()')
command! SetSpellLang exec('py detect_and_set_spelllang()')
python <<EOF
from glanguage import Translator
import vim
def detect_buffer_language():
t = Translator()
return t.detect(unicode(vim.current.buffer[0:3]))
def detect_language():
print detect_buffer_language().lang
def detect_and_set_spelllang():
l = detect_buffer_language()
print "Document language is " + l.lang
vim.command("set spell")
vim.command("set spelllang=" + l.lang_code)
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment