| 1 | " Vim plugin file |
| 2 | " |
| 3 | " Maintainer: Stefan Karlsson <stefan.74@comhem.se> |
| 4 | " Last Change: 1 September 2004 |
| 5 | " |
| 6 | " Purpose: To make <ctrl-a> and <ctrl-x> operate on the names of weekdays |
| 7 | " and months. |
| 8 | " |
| 9 | " TODO: Although it is possible to add any words you like as |
| 10 | " increase/decrease pairs, problems will arise when one word has |
| 11 | " two or more possible increments (or decrements). For instance, |
| 12 | " the 4th month is named "April" in both English and Swedish, but |
| 13 | " its increment is called "May" and "Maj", respectively. |
| 14 | " |
| 15 | " So, in order for the script to be generally applicable, I must |
| 16 | " find a way to toggle between all possible increments/decrements |
| 17 | " of a word. |
| 18 | |
| 19 | |
| 20 | if exists('loaded_monday') || &compatible |
| 21 | finish |
| 22 | endif |
| 23 | let loaded_monday = 1 |
| 24 | |
| 25 | function s:AddPair(word1, word2) |
| 26 | let w10 = tolower(a:word1) |
| 27 | let w11 = toupper(matchstr(w10, '.')) . matchstr(w10, '.*', 1) |
| 28 | let w12 = toupper(w10) |
| 29 | |
| 30 | let w20 = tolower(a:word2) |
| 31 | let w21 = toupper(matchstr(w20, '.')) . matchstr(w20, '.*', 1) |
| 32 | let w22 = toupper(w20) |
| 33 | |
| 34 | let s:words = s:words . w10 . ':' . w20 . ',' |
| 35 | let s:words = s:words . w11 . ':' . w21 . ',' |
| 36 | let s:words = s:words . w12 . ':' . w22 . ',' |
| 37 | endfunction |
| 38 | |
| 39 | let s:words = '' |
| 40 | |
| 41 | " add custom AddPair pattern |
| 42 | " 2004/10/14 |
| 43 | call <SID>AddPair('true', 'false') |
| 44 | call <SID>AddPair('false', 'true') |
| 45 | call <SID>AddPair('yes', 'no') |
| 46 | call <SID>AddPair('no', 'yes') |
| 47 | call <SID>AddPair('on', 'off') |
| 48 | call <SID>AddPair('off', 'on') |
| 49 | |
| 50 | call <SID>AddPair('mon', 'tue') |
| 51 | call <SID>AddPair('tue', 'wed') |
| 52 | call <SID>AddPair('wed', 'thu') |
| 53 | call <SID>AddPair('thu', 'fri') |
| 54 | call <SID>AddPair('fri', 'sat') |
| 55 | call <SID>AddPair('sat', 'sun') |
| 56 | call <SID>AddPair('sun', 'mon') |
| 57 | |
| 58 | call <SID>AddPair('jan', 'feb') |
| 59 | call <SID>AddPair('feb', 'mar') |
| 60 | call <SID>AddPair('mar', 'apr') |
| 61 | "call <SID>AddPair('apr', 'may') |
| 62 | "call <SID>AddPair('may', 'june') |
| 63 | "call <SID>AddPair('june', 'july') |
| 64 | "call <SID>AddPair('july', 'aug') |
| 65 | call <SID>AddPair('aug', 'sep') |
| 66 | call <SID>AddPair('sep', 'oct') |
| 67 | call <SID>AddPair('oct', 'nov') |
| 68 | call <SID>AddPair('nov', 'dec') |
| 69 | call <SID>AddPair('dec', 'jan') |
| 70 | |
| 71 | call <SID>AddPair('public', 'protected') |
| 72 | call <SID>AddPair('protected', 'private') |
| 73 | call <SID>AddPair('private', 'public') |
| 74 | |
| 75 | " default AddPair pattern |
| 76 | call <SID>AddPair('monday', 'tuesday') |
| 77 | call <SID>AddPair('tuesday', 'wednesday') |
| 78 | call <SID>AddPair('wednesday', 'thursday') |
| 79 | call <SID>AddPair('thursday', 'friday') |
| 80 | call <SID>AddPair('friday', 'saturday') |
| 81 | call <SID>AddPair('saturday', 'sunday') |
| 82 | call <SID>AddPair('sunday', 'monday') |
| 83 | |
| 84 | call <SID>AddPair('january', 'february') |
| 85 | call <SID>AddPair('february', 'march') |
| 86 | call <SID>AddPair('march', 'april') |
| 87 | call <SID>AddPair('april', 'may') |
| 88 | call <SID>AddPair('may', 'june') |
| 89 | call <SID>AddPair('june', 'july') |
| 90 | call <SID>AddPair('july', 'august') |
| 91 | call <SID>AddPair('august', 'september') |
| 92 | call <SID>AddPair('september', 'october') |
| 93 | call <SID>AddPair('october', 'november') |
| 94 | call <SID>AddPair('november', 'december') |
| 95 | call <SID>AddPair('december', 'january') |
| 96 | |
| 97 | |
| 98 | function s:MakeMapping(inc_or_dec) |
| 99 | if a:inc_or_dec == 'inc' || a:inc_or_dec == 'both' |
| 100 | nmap <silent> <c-a> :<c-u>call <SID>IncDec('inc')<cr> |
| 101 | endif |
| 102 | if a:inc_or_dec == 'dec' || a:inc_or_dec == 'both' |
| 103 | nmap <silent> <c-x> :<c-u>call <SID>IncDec('dec')<cr> |
| 104 | endif |
| 105 | endfunction |
| 106 | |
| 107 | function s:IncDec(inc_or_dec) |
| 108 | let N = (v:count < 1) ? 1 : v:count |
| 109 | let i = 0 |
| 110 | if a:inc_or_dec == 'inc' |
| 111 | while i < N |
| 112 | let w = expand('<cword>') |
| 113 | if s:words =~# '\<' . w . ':' |
| 114 | let n = match(s:words, w . ':\i\+\C') |
| 115 | let n = match(s:words, ':', n) |
| 116 | let a = matchstr(s:words, '\i\+', n) |
| 117 | execute "normal ciw" . a |
| 118 | else |
| 119 | nunmap <c-a> |
| 120 | execute "normal \<c-a>" |
| 121 | call <SID>MakeMapping('inc') |
| 122 | endif |
| 123 | let i = i + 1 |
| 124 | endwhile |
| 125 | else "inc_or_dec == 'dec' |
| 126 | while i < N |
| 127 | let w = expand('<cword>') |
| 128 | |
| 129 | if s:words =~# ':' . w . '\>' |
| 130 | let n = match(s:words, '\i\+\C:' . w) |
| 131 | let a = matchstr(s:words, '\i\+', n) |
| 132 | execute "normal ciw" . a |
| 133 | else |
| 134 | nunmap <c-x> |
| 135 | execute "normal \<c-x>" |
| 136 | call <SID>MakeMapping('dec') |
| 137 | endif |
| 138 | let i = i + 1 |
| 139 | |
| 140 | endwhile |
| 141 | endif |
| 142 | endfunction |
| 143 | |
| 144 | call <SID>MakeMapping('both') |
| 145 | |