From 757ad38b85ab59bc76f8140da21887e783acca4d Mon Sep 17 00:00:00 2001 From: Knyffen Date: Thu, 20 Jun 2024 11:57:24 +0200 Subject: [PATCH] Fix automatically setting spellfile when spelllang is set in the modeline --- init.vim | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/init.vim b/init.vim index 5f2ecd6..57eb398 100644 --- a/init.vim +++ b/init.vim @@ -1039,12 +1039,35 @@ augroup END " Add spell checking to LaTeX documents {{ let g:spellfile_URL = 'http://ftp.vim.org/vim/runtime/spell' function! SetLanguageSpecificSpellFile() + set spellfile= + + " Add the default spelling file if &spelllang =~ '^en' - setlocal spellfile+=~/.config/nvim/spell/en.utf-8.add + set spellfile+=~/.config/nvim/spell/en.utf-8.add endif if &spelllang =~ '^da' - setlocal spellfile+=~/.config/nvim/spell/dk.utf-8.add + set spellfile+=~/.config/nvim/spell/dk.utf-8.add endif + " zg or 1zg adds a word to the dictionary + + " Add a file specific wordlist for one-off words that shouldn't be part of + " the dictionary + if &filetype =~ 'tex\|markdown' + set spellfile+=oneoff.utf-8.add + endif + " 2zg adds a word to the dictionary + + " Add a LaTeX specific wordlist for e.g. chktex + if &filetype =~ 'tex' + set spellfile+=~/.config/nvim/spell/LaTeX.utf-8.add + endif + " 3zg adds a word to the dictionary + + " Add a Markdown specific wordlist + if &filetype =~ 'markdown' + set spellfile+=~/.config/nvim/spell/Markdown.utf-8.add + endif + " 3zg adds a word to the dictionary endfunction augroup spelling au! @@ -1061,23 +1084,8 @@ augroup END " Add a file for custom suggestions au FileType tex,markdown setlocal spellsuggest+=file:~/.config/nvim/spell/suggestions - " Add the default spelling file - au FileType tex,markdown execute SetLanguageSpecificSpellFile() - " au FileType tex,markdown setlocal spellfile+=~/.config/nvim/spell/en.utf-8.add - " zg or 1zg adds a word to the dictionary - - " Add a file specific wordlist for one-off words that shouldn't be part of - " the dictionary - au FileType tex,markdown setlocal spellfile+=oneoff.utf-8.add - " 2zg adds a word to the dictionary - - " Add a LaTeX specific wordlist for e.g. chktex - au FileType tex setlocal spellfile+=~/.config/nvim/spell/LaTeX.utf-8.add - " 3zg adds a word to the dictionary - - " Add a Markdown specific wordlist - au FileType markdown setlocal spellfile+=~/.config/nvim/spell/Markdown.utf-8.add - " 3zg adds a word to the dictionary + " Add the default spelling files + au BufWinEnter * execute SetLanguageSpecificSpellFile() " Disable spelling in math environments au FileType markdown syntax match texMath /\$[^$]\+\$/ contains=@NoSpell containedin=markdownBlock,markdownBlockquote