download

Sign in or create your account | Project List | Help

download Git Source Tree

Root/monday_custom.vim

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
20if exists('loaded_monday') || &compatible
21    finish
22endif
23let loaded_monday = 1
24
25function 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 . ','
37endfunction
38
39let s:words = ''
40
41" add custom AddPair pattern
42" 2004/10/14
43call <SID>AddPair('true', 'false')
44call <SID>AddPair('false', 'true')
45call <SID>AddPair('yes', 'no')
46call <SID>AddPair('no', 'yes')
47call <SID>AddPair('on', 'off')
48call <SID>AddPair('off', 'on')
49
50call <SID>AddPair('mon', 'tue')
51call <SID>AddPair('tue', 'wed')
52call <SID>AddPair('wed', 'thu')
53call <SID>AddPair('thu', 'fri')
54call <SID>AddPair('fri', 'sat')
55call <SID>AddPair('sat', 'sun')
56call <SID>AddPair('sun', 'mon')
57
58call <SID>AddPair('jan', 'feb')
59call <SID>AddPair('feb', 'mar')
60call <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')
65call <SID>AddPair('aug', 'sep')
66call <SID>AddPair('sep', 'oct')
67call <SID>AddPair('oct', 'nov')
68call <SID>AddPair('nov', 'dec')
69call <SID>AddPair('dec', 'jan')
70
71call <SID>AddPair('public', 'protected')
72call <SID>AddPair('protected', 'private')
73call <SID>AddPair('private', 'public')
74
75" default AddPair pattern
76call <SID>AddPair('monday', 'tuesday')
77call <SID>AddPair('tuesday', 'wednesday')
78call <SID>AddPair('wednesday', 'thursday')
79call <SID>AddPair('thursday', 'friday')
80call <SID>AddPair('friday', 'saturday')
81call <SID>AddPair('saturday', 'sunday')
82call <SID>AddPair('sunday', 'monday')
83
84call <SID>AddPair('january', 'february')
85call <SID>AddPair('february', 'march')
86call <SID>AddPair('march', 'april')
87call <SID>AddPair('april', 'may')
88call <SID>AddPair('may', 'june')
89call <SID>AddPair('june', 'july')
90call <SID>AddPair('july', 'august')
91call <SID>AddPair('august', 'september')
92call <SID>AddPair('september', 'october')
93call <SID>AddPair('october', 'november')
94call <SID>AddPair('november', 'december')
95call <SID>AddPair('december', 'january')
96
97
98function 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
105endfunction
106
107function 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
142endfunction
143
144call <SID>MakeMapping('both')
145

Archive Download this file

Branches:
master