" This file gives some macros to help type Ruby programs. set notimeout set smartindent set smarttab set autoindent set shiftwidth=2 noremap K :!ruby % nnoremap :if strpart(getline(1),0,21) !='#!/usr/math/bin/ruby'0put ='#!/usr/math/bin/ruby'put =''endif:if getline(3) != ""1put =''endif3Gi inoremap ;; ; inoremap ;e end inoremap ;h => inoremap " =Double('"','"') inoremap ` =Double('`','`') inoremap ' =Double("\'","\'") inoremap ( =Double("(",")") inoremap [ =Double("[","]") inoremap { =Double("{","}") function! s:Double(left,right) if strpart(getline(line(".")),col(".")-2,2) == a:left . a:right return "\s" else return a:left . a:right . "\" endif endfunction vnoremap `[ `>a]` vnoremap `( `>a)` vnoremap `{ `>a}` vnoremap `" `>a"` vnoremap `` `>a`` noremap :call DeleteBrackets() function! s:DeleteBrackets() let s:c = getline(line("."))[col(".") - 1] if s:c == '{' || c == '[' || c == '(' normal %x``x elseif s:c == '}' || s:c == ']' || s:c == ')' normal %%x``x`` elseif s:c == '"' exe "normal x/\"\x``" endif endfunction " The following macros automatically insert complete various ruby items. noremap :call DeleteBrackets() " To defuse the abbreviations. inoremap inoremap \| =DoubleBars() function! s:DoubleBars() if strpart(getline(line(".")),0,col(".")-2) =~ '[/#]' return "\|" else return "\|\|\" endif endfunction iab def =SpecialAbbrev("def") " iab else else " Taken care of by vim 6.0 indenting. iab elsif elsif iab for =For() iab if =SpecialAbbrev("if") iab case =Case() iab class =SpecialAbbrev("class") iab module =SpecialAbbrev("module") iab unless =SpecialAbbrev("unless") iab until =SpecialAbbrev("until") iab while =SpecialAbbrev("while") function! s:SpecialAbbrev(string) if strpart(getline(line(".")),0,col(".")-1) =~ '\S' " Not a blank line. return a:string else return a:string . "\end\kA" endif endfunction function! s:For() if strpart(getline(line(".")),0,col(".")-1) =~ '\S' " Not a blank line. return "for" else return "for in \end\k$3hi" endif endfunction function! s:Case() return "case\owhen \oend\2kA" endfunction iab do =DoAbbrev() function! s:DoAbbrev() if strpart(getline(line(".")),0,col(".")-1) =~ '^\s*\S*\s*$' return "do" . "\end\kA" else return "do" endif endfunction