aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-06-10 14:05:01 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-06-10 14:05:14 +1200
commitc0bab95ec716a6b68b11539c205623ed11d8c450 (patch)
tree1b1c41e87ee671b58edd47c349c4bbc732b00804
parentCorrect a badly copy-pasted sentence (diff)
downloaddotfiles-c0bab95ec716a6b68b11539c205623ed11d8c450.tar.gz
dotfiles-c0bab95ec716a6b68b11539c205623ed11d8c450.zip
Add uncommented code for spellfile extension
-rw-r--r--IDEAS.md4
-rw-r--r--vim/vimrc22
2 files changed, 22 insertions, 4 deletions
diff --git a/IDEAS.md b/IDEAS.md
index 6e098377..7c42cc96 100644
--- a/IDEAS.md
+++ b/IDEAS.md
@@ -33,7 +33,3 @@ Ideas
some point
* I'd like a Git hook that pre-fills out "Version X.Y.Z" if making an annotated
tag named `vX.Y.Z`.
-* I'd like to make the zG command in Vim a bit more useful by maintaining
- a per-file cache of added words, indexed by path, mapping it to 2zg or 3zg
- rather like Steve Losh does. I wouldn't think it would be too hard;
- 'spellfile' is a buffer-local option.
diff --git a/vim/vimrc b/vim/vimrc
index 95ca61ae..737b9fd6 100644
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -902,6 +902,28 @@ if $MYVIM !=# '' && $MYVIM !~# '[*?[|;&<>\r\n]'
set thesaurus^=$MYVIM/ref/thesaurus.txt
endif
+EnsureDir $MYVIM/cache/spell
+
+let spellfile = join([
+ \ substitute(v:lang, '_.*', '', ''),
+ \ &encoding
+ \ ], '.') . '.add'
+execute 'set spellfile=$MYVIM/cache/spell/'.spellfile
+
+EnsureDir $MYVIM/cache/spell/local
+
+function! AddLocalSpellfile() abort
+ let spellfile = join([
+ \ substitute(expand('%:p'), '[^0-9A-Za-z_.-]', '%', 'g'),
+ \ substitute(v:lang, '_.*', '', ''),
+ \ &encoding
+ \ ], '.') . '.add'
+ setlocal spellfile<
+ execute 'setlocal spellfile+=$MYVIM/cache/spell/local/'.spellfile
+ndfunction!
+autocmd vimrc BufRead *
+ \ call AddLocalSpellfile() | nnoremap <buffer> zG 2zg
+
" Use all of the filetype detection, plugin, and indent support available.
" I define my own filetype.vim and scripts.vim files for filetype detection,
" in a similar but not identical form to the stock runtime files. I also