" Vim plugin file " " Maintainer: Stefan Karlsson " Last Change: 6 May 2005 " " Patch: http://nanasi.jp/articles/vim/monday_vim.html " Patch: G-HAL Wed,16 Aug,2006 " Debug: G-HAL Tue,13 Jan,2009 " " Purpose: To make and operate on the names of weekdays " and months. Also to make them operate on text such as 1st, 2nd, " 3rd, and so on. " " 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 successors (or predecessors). For instance, " the 4th month is named "April" in both English and Swedish, but " its successor 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 let s:words = '' let s:numbers = '' function s:Add_word_pair(word1, word2) let w10 = tolower(a:word1) let w11 = toupper(matchstr(a:word1, '.')) . matchstr(w10, '.*', 1) let w12 = toupper(a:word1) let w20 = tolower(a:word2) let w21 = toupper(matchstr(a:word2, '.')) . matchstr(w20, '.*', 1) let w22 = toupper(a:word2) let s:words = s:words . ' ' . w10 . ' : ' . w20 . ' ,' let s:words = s:words . ' ' . w11 . ' : ' . w21 . ' ,' let s:words = s:words . ' ' . w12 . ' : ' . w22 . ' ,' endfunction function s:Add_caseword_pair(word1, word2) let s:words = s:words . ' ' . a:word1 . ' : ' . a:word2 . ' ,' endfunction function s:Add_number_suffix(number, suffix) let s0 = tolower(a:suffix) let s1 = toupper(a:suffix) let s:numbers = s:numbers . 's' . a:number . s0 . ',' let s:numbers = s:numbers . 'l' . a:number . s1 . ',' endfunction call Add_word_pair('monday', 'tuesday') call Add_word_pair('tuesday', 'wednesday') call Add_word_pair('wednesday', 'thursday') call Add_word_pair('thursday', 'friday') call Add_word_pair('friday', 'saturday') call Add_word_pair('saturday', 'sunday') call Add_word_pair('sunday', 'monday') call Add_word_pair('mon', 'tue') call Add_word_pair('tue', 'wed') call Add_word_pair('wed', 'thu') call Add_word_pair('wed', 'thr') " only for THR -(dec)-> WED call Add_word_pair('thu', 'fri') call Add_word_pair('thr', 'fri') " only for THR -(inc)-> FRI call Add_word_pair('fri', 'sat') call Add_word_pair('sat', 'sun') call Add_word_pair('sun', 'mon') call Add_caseword_pair('月', '火') call Add_caseword_pair('火', '水') call Add_caseword_pair('水', '木') call Add_caseword_pair('木', '金') call Add_caseword_pair('金', '土') call Add_caseword_pair('土', '日') call Add_caseword_pair('日', '月') call Add_word_pair('january', 'february') call Add_word_pair('february', 'march') call Add_word_pair('march', 'april') "call Add_word_pair('april', 'may') "call Add_word_pair('may', 'june') call Add_word_pair('june', 'july') call Add_word_pair('july', 'august') call Add_word_pair('august', 'september') call Add_word_pair('september', 'october') call Add_word_pair('october', 'november') call Add_word_pair('november', 'december') call Add_word_pair('december', 'january') call Add_word_pair('jan', 'feb') call Add_word_pair('feb', 'mar') call Add_word_pair('mar', 'apr') call Add_word_pair('apr', 'may') call Add_word_pair('may', 'jun') call Add_word_pair('jun', 'jul') call Add_word_pair('jul', 'aug') call Add_word_pair('aug', 'sep') call Add_word_pair('sep', 'oct') call Add_word_pair('oct', 'nov') call Add_word_pair('nov', 'dec') call Add_word_pair('dec', 'jan') call Add_caseword_pair('睦月', '如月') call Add_caseword_pair('如月', '弥生') call Add_caseword_pair('弥生', '卯月') call Add_caseword_pair('卯月', '皐月') call Add_caseword_pair('皐月', '水無月') call Add_caseword_pair('水無月', '文月') call Add_caseword_pair('文月', '葉月') call Add_caseword_pair('葉月', '長月') call Add_caseword_pair('長月', '神無月') call Add_caseword_pair('神無月', '霜月') call Add_caseword_pair('霜月', '師走') call Add_caseword_pair('師走', '睦月') call Add_number_suffix('11', 'th') call Add_number_suffix('12', 'th') call Add_number_suffix('13', 'th') call Add_number_suffix( '0', 'th') call Add_number_suffix( '1', 'st') call Add_number_suffix( '2', 'nd') call Add_number_suffix( '3', 'rd') call Add_number_suffix( '4', 'th') call Add_number_suffix( '5', 'th') call Add_number_suffix( '6', 'th') call Add_number_suffix( '7', 'th') call Add_number_suffix( '8', 'th') call Add_number_suffix( '9', 'th') call Add_word_pair('public', 'protected') call Add_word_pair('protected', 'private') call Add_word_pair('private', 'public') call Add_word_pair('true', 'false') call Add_word_pair('false', 'true') call Add_word_pair('yes', 'no') call Add_word_pair('no', 'yes') call Add_word_pair('on', 'off') call Add_word_pair('off', 'on') function s:Find_nr_suffix(w, nr) let n1 = matchstr(a:nr, '\d\>') let n2 = matchstr(a:nr, '\d\d\>') let m = matchstr(a:w, '\D\+', 1) let m = matchstr(s:numbers, '[sl]\d\+' . m) let m = matchstr(m, '.') let c1 = (n1 != "") ? match(s:numbers, m . n1 . '\D\+') : -1 let c2 = (n2 != "") ? match(s:numbers, m . n2 . '\D\+') : -1 if c2 >= 0 return matchstr(s:numbers, '\D\+\>', c2) else return matchstr(s:numbers, '\D\+\>', c1) endif endfunction function s:Goto_word_head(w) let cur = getpos(".") let s = search( a:w, 'bcW', cur[1] ) let bw = getpos(".") if (s < 1) || ((bw[2] + strlen(a:w)) <= cur[2]) call setpos(".", cur) call search( a:w, 'cW', cur[1] ) return endif return endfunction function s:Goto_first_nonblank() call cursor(0, col('.') - 1) call search('\S') endfunction function s:Increase() let s:set_ignorecase = &ignorecase setlocal noignorecase " for match() let N = (v:count < 1) ? 1 : v:count let i = 0 while i < N let w = expand('') let w = matchstr(w, "[^ :,]\*") if s:words =~# ' ' . w . ' : ' let n = match(s:words, ' ' . w . ' : [^ :,]\+ ,') let n = match(s:words, ' : ', n) let a = matchstr(s:words, '[^ :,]\+', n) call Goto_word_head(w) execute "normal! ciw" . a elseif w =~# '\<-\?\d\+\D\+\>' && s:numbers =~# '\d\+' . matchstr(w, '\D\+', 1) . ',' let a = matchstr(w, '-\?\d\+') let a = a + 1 let s = Find_nr_suffix(w, a) call Goto_first_nonblank() execute "normal! ciW" . a . s else execute "normal! \" endif let i = i + 1 endwhile if s:set_ignorecase == 0 setlocal ignorecase endif endfunction function s:Decrease() let s:set_ignorecase = &ignorecase setlocal noignorecase " for match() let N = (v:count < 1) ? 1 : v:count let i = 0 while i < N let w = expand('') let w = matchstr(w, "[^ :,]\*") if s:words =~# ' : ' . w . ' ,' let n = match(s:words, ' [^ :,]\+ : ' . w . ' ,') let a = matchstr(s:words, '[^ :,]\+', n) call Goto_word_head(w) execute "normal! ciw" . a elseif w =~# '\<-\?\d\+\D\+\>' && s:numbers =~# '\d\+' . matchstr(w, '\D\+', 1) . ',' let a = matchstr(w, '-\?\d\+') let a = a - 1 let s = Find_nr_suffix(w, a) call Goto_first_nonblank() execute "normal! ciW" . a . s else execute "normal! \" endif let i = i + 1 endwhile if s:set_ignorecase == 0 setlocal ignorecase endif endfunction nmap :call Increase() nmap :call Decrease() " [ End of File ]