" Vim plugin file " " Maintainer: Stefan Karlsson " Last Change: 1 September 2004 " " Purpose: To make and operate on the names of weekdays " and months. " " TODO: Although it is possible to add any words you like as " increase/decrease pairs, problems will arise when one word has " two or more possible increments (or decrements). For instance, " the 4th month is named "April" in both English and Swedish, but " its increment is called "May" and "Maj", respectively. " " So, in order for the script to be generally applicable, I must " find a way to toggle between all possible increments/decrements " of a word. if exists('loaded_monday') || &compatible finish endif let loaded_monday = 1 function s:AddPair(word1, word2) let w10 = tolower(a:word1) let w11 = toupper(matchstr(w10, '.')) . matchstr(w10, '.*', 1) let w12 = toupper(w10) let w20 = tolower(a:word2) let w21 = toupper(matchstr(w20, '.')) . matchstr(w20, '.*', 1) let w22 = toupper(w20) let s:words = s:words . w10 . ':' . w20 . ',' let s:words = s:words . w11 . ':' . w21 . ',' let s:words = s:words . w12 . ':' . w22 . ',' endfunction let s:words = '' call AddPair('monday', 'tuesday') call AddPair('tuesday', 'wednesday') call AddPair('wednesday', 'thursday') call AddPair('thursday', 'friday') call AddPair('friday', 'saturday') call AddPair('saturday', 'sunday') call AddPair('sunday', 'monday') call AddPair('january', 'february') call AddPair('february', 'march') call AddPair('march', 'april') call AddPair('april', 'may') call AddPair('may', 'june') call AddPair('june', 'july') call AddPair('july', 'august') call AddPair('august', 'september') call AddPair('september', 'october') call AddPair('october', 'november') call AddPair('november', 'december') call AddPair('december', 'january') function s:MakeMapping(inc_or_dec) if a:inc_or_dec == 'inc' || a:inc_or_dec == 'both' nmap :call IncDec('inc') endif if a:inc_or_dec == 'dec' || a:inc_or_dec == 'both' nmap :call IncDec('dec') endif endfunction function s:IncDec(inc_or_dec) let N = (v:count < 1) ? 1 : v:count let i = 0 if a:inc_or_dec == 'inc' while i < N let w = expand('') if s:words =~# '\<' . w . ':' let n = match(s:words, w . ':\i\+\C') let n = match(s:words, ':', n) let a = matchstr(s:words, '\i\+', n) execute "normal ciw" . a else nunmap execute "normal \" call MakeMapping('inc') endif let i = i + 1 endwhile else "inc_or_dec == 'dec' while i < N let w = expand('') if s:words =~# ':' . w . '\>' let n = match(s:words, '\i\+\C:' . w) let a = matchstr(s:words, '\i\+', n) execute "normal ciw" . a else nunmap execute "normal \" call MakeMapping('dec') endif let i = i + 1 endwhile endif endfunction call MakeMapping('both')