├── doc └── dialect.txt ├── README.md ├── autoload └── dialect.vim └── plugin └── dialect.vim /doc/dialect.txt: -------------------------------------------------------------------------------- 1 | *dialect.txt* Project specific spellfiles 2 | 3 | Author: Daniel B. Marques 4 | License: Same as Vim (see |license|) 5 | 6 | 7 | ============================================================================== 8 | 9 | Dialect is a simple plugin that persists the words added with zG and zW to 10 | a spellfile specific to the current directory. 11 | 12 | 13 | Usage *dialect-usage* 14 | ----- 15 | 16 | - Keep using zg and zw the way you always did. 17 | 18 | - The words you add with zG and zW will be added to 19 | "./.dialect.{encoding}.add". 20 | 21 | - By default, dialect.vim uses a 'spellfile' for each directory. If you 22 | want a different 'spellfile' for each specific file, add this to your 23 | .vimrc: 24 | > 25 | let g:dialectmode = 'file' 26 | < 27 | 28 | You can also add a file called ".dialectmain" to a directory and all 29 | files in its subdirectories will use the 'spellfile' there. 30 | 31 | vim:tw=78:ts=8:ft=help:norl: 32 | 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dialect.vim 2 | 3 | A simple plugin that persists the words added with `zG` and `zW` to a 4 | `spellfile` specific to the current file or directory. 5 | 6 | 7 | ## Usage 8 | 9 | - Keep using `zg` and `zw` the way you always did. 10 | 11 | - The words you add with `zG` and `zW` will be added to 12 | `./.dialect.{encoding}.add`. 13 | 14 | - By default, `dialect.vim` uses a `spellfile` for each directory. If you want 15 | a different `spellfile` for each specific file, add this to your `.vimrc`: 16 | `let g:dialectmode = 'file'`. You can also add a file called `.dialectmain` 17 | to a directory and all files in its subdirectories will use the `spellfile` 18 | there. 19 | 20 | That's it! 21 | 22 | 23 | ## See also 24 | 25 | You may also be interested in my other plugins: 26 | 27 | - [Ditto: highlight overused words](https://github.com/dbmrq/vim-ditto) :speak_no_evil: 28 | - [Redacted: the best way to ████ the ████](https://github.com/dbmrq/vim-redacted) :no_mouth: 29 | - [Chalk: better fold markers](https://github.com/dbmrq/vim-chalk) :pencil2: 30 | - [Howdy: a tiny MRU start screen for Vim](https://github.com/dbmrq/vim-howdy) :wave: 31 | 32 | 33 | -------------------------------------------------------------------------------- /autoload/dialect.vim: -------------------------------------------------------------------------------- 1 | " dialect.vim - Project specific spellfiles 2 | " Author: Daniel B. Marques 3 | " Version: 0.2 4 | " License: Same as Vim 5 | 6 | 7 | if exists("g:autoloaded_dialect") | finish | endif 8 | let g:autoloaded_dialect = 1 9 | 10 | function! dialect#getMainDir() 11 | let l:path = expand('%:p:h') 12 | while l:path != fnamemodify(l:path, ':h') 13 | if !empty(glob(l:path . '/.dialectmain')) 14 | return l:path 15 | endif 16 | let l:path = fnamemodify(l:path, ':h') 17 | endwhile 18 | return expand('%:p:h') 19 | endfunction 20 | 21 | function! dialect#localSpell(cmd) 22 | call DialectInit() 23 | let l:count = b:dialectcount > 0 ? b:dialectcount : '' 24 | execute "normal! " . l:count . tolower(a:cmd) 25 | endfunction 26 | 27 | function! dialect#localSpellV(cmd) 28 | call DialectInit() 29 | let l:count = b:dialectcount > 0 ? b:dialectcount : '' 30 | execute "normal! gv" . l:count . tolower(a:cmd) 31 | endfunction 32 | 33 | function! dialect#globalSpell(cmd) 34 | call DialectInit() 35 | if b:dialectcount > 1 || matchstr(a:cmd, '\d') >= 1 36 | execute "normal! " . substitute(a:cmd, '0', '', '') 37 | else 38 | let l:spellfile = &l:spellfile 39 | setlocal spellfile= 40 | execute "normal! " . substitute(a:cmd, '0', '', '') 41 | let &l:spellfile = l:spellfile 42 | endif 43 | endfunction 44 | 45 | -------------------------------------------------------------------------------- /plugin/dialect.vim: -------------------------------------------------------------------------------- 1 | " dialect.vim - Project specific spellfiles 2 | " Author: Daniel B. Marques 3 | " Version: 0.2 4 | " License: Same as Vim 5 | 6 | 7 | if exists("g:loaded_dialect") | finish | endif 8 | let g:loaded_dialect = 1 9 | 10 | augroup Dialect 11 | au! 12 | au BufNewFile,BufRead * call DialectInit() 13 | augroup END 14 | 15 | function! DialectInit() 16 | let encoding = &l:fileencoding == '' ? &l:encoding : &l:fileencoding 17 | if exists('g:dialectmode') && tolower(g:dialectmode) == 'file' 18 | let tail = '/.' . expand('%:t') . '.' . encoding . '.add' 19 | let b:dialectfile = expand('%:p:h') . tail 20 | else 21 | let tail = '/.dialect.' . encoding . '.add' 22 | let b:dialectfile = dialect#getMainDir() . tail 23 | endif 24 | let b:dialectfile = escape(b:dialectfile, ',') 25 | if &l:spellfile == "" 26 | let &l:spellfile = b:dialectfile 27 | elseif !(&l:spellfile =~ tail) 28 | let &l:spellfile .= "," . b:dialectfile 29 | endif 30 | let b:dialectcount = index(split(&l:spellfile, ","), b:dialectfile) + 1 31 | endfunction 32 | 33 | nnoremap zG :call dialect#localSpell("zG") 34 | nnoremap zW :call dialect#localSpell("zW") 35 | nnoremap zuG :call dialect#localSpell("zuG") 36 | nnoremap zuW :call dialect#localSpell("zuW") 37 | vnoremap zG :call dialect#localSpellV("zG") 38 | vnoremap zW :call dialect#localSpellV("zW") 39 | vnoremap zuG :call dialect#localSpellV("zuG") 40 | vnoremap zuW :call dialect#localSpellV("zuW") 41 | nnoremap zg :call dialect#globalSpell(v:count . "zg") 42 | nnoremap zw :call dialect#globalSpell(v:count . "zw") 43 | nnoremap zug :call dialect#globalSpell(v:count . "zug") 44 | nnoremap zuw :call dialect#globalSpell(v:count . "zuw") 45 | vnoremap zg :call dialect#globalSpell("gv" . v:count . "zg") 46 | vnoremap zw :call dialect#globalSpell("gv" . v:count . "zw") 47 | vnoremap zug :call dialect#globalSpell("gv" . v:count . "zug") 48 | vnoremap zuw :call dialect#globalSpell("gv" . v:count . "zuw") 49 | 50 | --------------------------------------------------------------------------------