From 5504e15411b0f682f3415677e65cbf03d6339d50 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 28 Aug 2016 16:48:10 -0400 Subject: First version of 'spellcycle' plugin A new plugin that cycles through a list of languages to use when spell checking. Using a couple of mappings, we can quickly change the `spelllang` to the language we want to write or read in. Languages are currently set to English and French, since those are the two that I use. The mappings are bound to `[l` and `]l` (in unimpaired.vim style) since those didn't seem to be used by anything. --- bundle/spellcycle/autoload/spellcycle.vim | 16 ++++++++++++++++ bundle/spellcycle/plugin/spellcycle.vim | 11 +++++++++++ 2 files changed, 27 insertions(+) create mode 100644 bundle/spellcycle/autoload/spellcycle.vim create mode 100644 bundle/spellcycle/plugin/spellcycle.vim diff --git a/bundle/spellcycle/autoload/spellcycle.vim b/bundle/spellcycle/autoload/spellcycle.vim new file mode 100644 index 0000000..6f4b703 --- /dev/null +++ b/bundle/spellcycle/autoload/spellcycle.vim @@ -0,0 +1,16 @@ +" Cycle +" Cycle the 'spelllang' option through a set of languages. The `direction` +" argument specifies whether to move left or right (and how much to move) in +" the list. +" +" Derived from `CycleLang` as written by kev here: +" http://stackoverflow.com/questions/12006508/vim-how-to-cycle-through-a-list-of-options-using-the-same-key/12006781#12006781 +function! spellcycle#Cycle(direction) + let languages = ['en', 'fr'] + + let i = index(languages, &spelllang) + let cycled_index = (i + a:direction) % len(languages) + let &spelllang = languages[cycled_index] + + set spelllang? +endfunction diff --git a/bundle/spellcycle/plugin/spellcycle.vim b/bundle/spellcycle/plugin/spellcycle.vim new file mode 100644 index 0000000..9ae3bfe --- /dev/null +++ b/bundle/spellcycle/plugin/spellcycle.vim @@ -0,0 +1,11 @@ +if exists('g:loaded_spellcycle') + finish +endif +let g:loaded_spellcycle = 1 + + +nnoremap spellcycle_Left :call spellcycle#Cycle(-1) +nnoremap spellcycle_Right :call spellcycle#Cycle(1) + +nmap [l spellcycle_Left +nmap ]l spellcycle_Right -- cgit v1.2.3