work/0000775000000000000000000000000014775444730006747 5ustar work/.gitignore0000664000000000000000000000000414775444730010731 0ustar .pc work/AlignPlugin/0000775000000000000000000000000014775444730011160 5ustar work/AlignPlugin/autoload/0000775000000000000000000000000014775444730012770 5ustar work/AlignPlugin/autoload/Align.vim0000664000000000000000000011473714775444730014554 0ustar " Align: tool to align multiple fields based on one or more separators " Author: Charles E. Campbell " Date: Mar 12, 2013 " Version: 37 " GetLatestVimScripts: 294 1 :AutoInstall: Align.vim " GetLatestVimScripts: 1066 1 :AutoInstall: cecutil.vim " Copyright: Copyright (C) 1999-2012 Charles E. Campbell {{{1 " Permission is hereby granted to use and distribute this code, " with or without modifications, provided that this copyright " notice is copied with it. Like anything else that's free, " Align.vim is provided *as is* and comes with no warranty " of any kind, either expressed or implied. By using this " plugin, you agree that in no event will the copyright " holder be liable for any damages resulting from the use " of this software. " " Romans 1:16,17a : For I am not ashamed of the gospel of Christ, for it is {{{1 " the power of God for salvation for everyone who believes; for the Jew first, " and also for the Greek. For in it is revealed God's righteousness from " faith to faith. "redraw!|call DechoSep()|call inputsave()|call input("Press to continue")|call inputrestore() " --------------------------------------------------------------------- " Load Once: {{{1 if exists("g:loaded_Align") || &cp finish endif let g:loaded_Align = "v37" if v:version < 700 echohl WarningMsg echo "***warning*** this version of Align needs vim 7.0" echohl Normal finish endif let s:keepcpo= &cpo set cpo&vim "DechoTabOn " --------------------------------------------------------------------- " Debugging Support: {{{1 "if !exists("g:loaded_Decho") | runtime plugin/Decho.vim | endif " --------------------------------------------------------------------- " Options: {{{1 if !exists("g:Align_xstrlen") if exists("g:drawit_xstrlen") let g:Align_xstrlen= g:drawit_xstrlen elseif exists("g:netrw_xstrlen") let g:Align_xstrlen= g:netrw_xstrlen elseif &enc == "latin1" || !has("multi_byte") let g:Align_xstrlen= 0 else let g:Align_xstrlen= 1 endif endif " --------------------------------------------------------------------- " Align#AlignCtrl: enter alignment patterns here {{{1 " " Styles = all alignment-break patterns are equivalent " C cycle through alignment-break pattern(s) " l left-justified alignment " r right-justified alignment " c center alignment " - skip separator, treat as part of field " : treat rest of line as field " + repeat previous [lrc] style " < left justify separators " > right justify separators " | center separators " " Builds = s:AlignPat s:AlignCtrl s:AlignPatQty " C s:AlignPat s:AlignCtrl s:AlignPatQty " p s:AlignPrePad " P s:AlignPostPad " w s:AlignLeadKeep " W s:AlignLeadKeep " I s:AlignLeadKeep " l s:AlignStyle " r s:AlignStyle " - s:AlignStyle " + s:AlignStyle " : s:AlignStyle " c s:AlignStyle " g s:AlignGPat " v s:AlignVPat " < s:AlignSep " > s:AlignSep " | s:AlignSep fun! Align#AlignCtrl(...) " call Dfunc("Align#AlignCtrl(...) a:0=".a:0) " save options that may be changed later call s:SaveUserOptions() " turn ignorecase off setlocal noic " clear visual mode so that old visual-mode selections don't " get applied to new invocations of Align(). if v:version < 602 if !exists("s:Align_gavemsg") let s:Align_gavemsg= 1 echomsg "Align needs at least Vim version 6.2 to clear visual-mode selection" endif elseif exists("s:dovisclear") " call Decho("clearing visual mode a:0=".a:0." a:1<".a:1.">") let clearvmode= visualmode(1) endif " set up a list akin to an argument list if a:0 > 0 let A= s:QArgSplitter(a:1) else let A=[0] endif if A[0] > 0 let style = A[1] " Check for bad separator patterns (zero-length matches) " (but zero-length patterns for g/v is ok) if style !~# '[gv]' let ipat= 2 while ipat <= A[0] if "" =~ A[ipat] echoerr "(AlignCtrl) separator<".A[ipat]."> matches zero-length string" call s:RestoreUserOptions() " call Dret("Align#AlignCtrl") return endif let ipat= ipat + 1 endwhile endif endif " call Decho("(AlignCtrl) passed bad-separator pattern check (no zero-length matches)") " call Decho("(AlignCtrl) A[0]=".A[0]) if !exists("s:AlignStyle") let s:AlignStyle= 'l' endif if !exists("s:AlignPrePad") let s:AlignPrePad= 0 endif if !exists("s:AlignPostPad") let s:AlignPostPad= 0 endif if !exists("s:AlignLeadKeep") let s:AlignLeadKeep= 'w' endif if A[0] == 0 " ---------------------- " List current selection " ---------------------- if !exists("s:AlignPatQty") let s:AlignPatQty= 0 endif echo "AlignCtrl<".s:AlignCtrl."> qty=".s:AlignPatQty." AlignStyle<".s:AlignStyle."> Padding<".s:AlignPrePad."|".s:AlignPostPad."> LeadingWS=".s:AlignLeadKeep." AlignSep=".s:AlignSep " call Decho("(AlignCtrl) AlignCtrl<".s:AlignCtrl."> qty=".s:AlignPatQty." AlignStyle<".s:AlignStyle."> Padding<".s:AlignPrePad."|".s:AlignPostPad."> LeadingWS=".s:AlignLeadKeep." AlignSep=".s:AlignSep) if exists("s:AlignGPat") && !exists("s:AlignVPat") echo "AlignGPat<".s:AlignGPat.">" elseif !exists("s:AlignGPat") && exists("s:AlignVPat") echo "AlignVPat<".s:AlignVPat.">" elseif exists("s:AlignGPat") && exists("s:AlignVPat") echo "AlignGPat<".s:AlignGPat."> AlignVPat<".s:AlignVPat.">" endif let ipat= 1 while ipat <= s:AlignPatQty echo "Pat".ipat."<".s:AlignPat_{ipat}.">" " call Decho("(AlignCtrl) Pat".ipat."<".s:AlignPat_{ipat}.">") let ipat= ipat + 1 endwhile else " ---------------------------------- " Process alignment control settings " ---------------------------------- " call Decho("process the alignctrl settings") " call Decho("style<".style.">") if style ==? "default" " Default: preserve initial leading whitespace, left-justified, " alignment on '=', one space padding on both sides if exists("s:AlignCtrlStackQty") " clear AlignCtrl stack while s:AlignCtrlStackQty > 0 call Align#AlignPop() endwhile unlet s:AlignCtrlStackQty endif " Set AlignCtrl to its default value call Align#AlignCtrl("Ilp1P1=<",'=') call Align#AlignCtrl("g") call Align#AlignCtrl("v") let s:dovisclear = 1 call s:RestoreUserOptions() " call Dret("Align#AlignCtrl") return endif if style =~# 'm' " map support: Do an AlignPush now and the next call to Align() " will do an AlignPop at exit " call Decho("style case m: do AlignPush") call Align#AlignPush() let s:DoAlignPop= 1 endif " = : record a list of alignment patterns that are equivalent if style =~# "=" || (A[0] >= 2 && style !~# "C" && s:AlignCtrl =~# '=') " call Decho("style case =: record list of equiv alignment patterns") let s:AlignCtrl = '=' if A[0] >= 2 let s:AlignPatQty= 1 let s:AlignPat_1 = A[2] let ipat = 3 while ipat <= A[0] let s:AlignPat_1 = s:AlignPat_1.'\|'.A[ipat] let ipat = ipat + 1 endwhile let s:AlignPat_1= '\('.s:AlignPat_1.'\)' " call Decho("AlignCtrl<".s:AlignCtrl."> AlignPat<".s:AlignPat_1.">") endif "c : cycle through alignment pattern(s) elseif style =~# 'C' || (A[0] >= 2 && s:AlignCtrl =~# '=') " call Decho("style case C: cycle through alignment pattern(s)") let s:AlignCtrl = 'C' if A[0] >= 2 let s:AlignPatQty= A[0] - 1 let ipat = 1 while ipat < A[0] let s:AlignPat_{ipat}= A[ipat+1] " call Decho("AlignCtrl<".s:AlignCtrl."> AlignQty=".s:AlignPatQty." AlignPat_".ipat."<".s:AlignPat_{ipat}.">") let ipat= ipat + 1 endwhile endif endif if style =~# 'p' let s:AlignPrePad= substitute(style,'^.*p\(\d\+\).*$','\1','') " call Decho("style case p".s:AlignPrePad.": pre-separator padding") if s:AlignPrePad == "" echoerr "(AlignCtrl) 'p' needs to be followed by a numeric argument'" call s:RestoreUserOptions() " call Dret("Align#AlignCtrl") return endif endif if style =~# 'P' let s:AlignPostPad= substitute(style,'^.*P\(\d\+\).*$','\1','') " call Decho("style case P".s:AlignPostPad.": post-separator padding") if s:AlignPostPad == "" echoerr "(AlignCtrl) 'P' needs to be followed by a numeric argument'" call s:RestoreUserOptions() " call Dret("Align#AlignCtrl") return endif endif if style =~# 'w' " call Decho("style case w: ignore leading whitespace") let s:AlignLeadKeep= 'w' elseif style =~# 'W' " call Decho("style case W: keep leading whitespace") let s:AlignLeadKeep= 'W' elseif style =~# 'I' " call Decho("style case I: retain initial leading whitespace") let s:AlignLeadKeep= 'I' endif if style =~# 'g' " first list item is a "g" selector pattern " call Decho("style case g: global selector pattern") if A[0] < 2 if exists("s:AlignVPat") unlet s:AlignVPat " call Decho("unlet s:AlignGPat") endif else let s:AlignGPat= A[2] " call Decho("s:AlignGPat<".s:AlignGPat.">") endif elseif style =~# 'v' " first list item is a "v" selector pattern " call Decho("style case v: global selector anti-pattern") if A[0] < 2 if exists("s:AlignGPat") unlet s:AlignGPat " call Decho("unlet s:AlignVPat") endif else let s:AlignVPat= A[2] " call Decho("s:AlignVPat<".s:AlignVPat.">") endif endif "[-lrc+:] : set up s:AlignStyle if style =~# '[-lrc+:*]' " call Decho("style case [-lrc+:]: field justification") let s:AlignStyle= substitute(style,'[^-lrc:+*]','','g') " call Decho("AlignStyle<".s:AlignStyle.">") endif "[<>|] : set up s:AlignSep if style =~# '[<>|]' " call Decho("style case [-lrc+:]: separator justification") let s:AlignSep= substitute(style,'[^<>|]','','g') " call Decho("AlignSep ".s:AlignSep) endif endif " sanity if !exists("s:AlignCtrl") let s:AlignCtrl= '=' endif " restore options and return call s:RestoreUserOptions() " call Dret("Align#AlignCtrl ".s:AlignCtrl.'p'.s:AlignPrePad.'P'.s:AlignPostPad.s:AlignLeadKeep.s:AlignStyle) return s:AlignCtrl.'p'.s:AlignPrePad.'P'.s:AlignPostPad.s:AlignLeadKeep.s:AlignStyle endfun " --------------------------------------------------------------------- " s:MakeSpace: returns a string with spacecnt blanks {{{1 fun! s:MakeSpace(spacecnt) " call Dfunc("MakeSpace(spacecnt=".a:spacecnt.")") let str = "" let spacecnt = a:spacecnt while spacecnt > 0 let str = str . " " let spacecnt = spacecnt - 1 endwhile " call Dret("MakeSpace <".str.">") return str endfun " --------------------------------------------------------------------- " Align#Align: align selected text based on alignment pattern(s) {{{1 fun! Align#Align(hasctrl,...) range " call Dfunc("Align#Align(hasctrl=".a:hasctrl.",...) a:0=".a:0) " sanity checks if string(a:hasctrl) != "0" && string(a:hasctrl) != "1" echohl Error|echo 'usage: Align#Align(hasctrl<'.a:hasctrl.'> (should be 0 or 1),"separator(s)" (you have '.a:0.') )'|echohl None " call Dret("Align#Align") return endif if exists("s:AlignStyle") && s:AlignStyle == ":" echohl Error |echo '(Align#Align) your AlignStyle is ":", which implies "do-no-alignment"!'|echohl None " call Dret("Align#Align") return endif " save user options call s:SaveUserOptions() " set up a list akin to an argument list if a:0 > 0 let A= s:QArgSplitter(a:1) else let A=[0] endif " if :Align! was used, then the first argument is (should be!) an AlignCtrl string " Note that any alignment control set this way will be temporary. let hasctrl= a:hasctrl " call Decho("hasctrl=".hasctrl) if a:hasctrl && A[0] >= 1 " call Decho("Align! : using A[1]<".A[1]."> for AlignCtrl") if A[1] =~ '[gv]' let hasctrl= hasctrl + 1 call Align#AlignCtrl('m') call Align#AlignCtrl(A[1],A[2]) " call Decho("Align! : also using A[2]<".A[2]."> for AlignCtrl") elseif A[1] !~ 'm' call Align#AlignCtrl(A[1]."m") else call Align#AlignCtrl(A[1]) endif endif " Check for bad separator patterns (zero-length matches) let ipat= 1 + hasctrl while ipat <= A[0] if "" =~ A[ipat] echoerr "(Align) separator<".A[ipat]."> matches zero-length string" call s:RestoreUserOptions() " call Dret("Align#Align") return endif let ipat= ipat + 1 endwhile " record current search pattern for subsequent restoration " (these are all global-only options) set noic report=10000 nohls if A[0] > hasctrl " Align will accept a list of separator regexps " call Decho("A[0]=".A[0].": accepting list of separator regexp") if s:AlignCtrl =~# "=" "= : consider all separators to be equivalent " call Decho("AlignCtrl: record list of equivalent alignment patterns") let s:AlignCtrl = '=' let s:AlignPat_1 = A[1 + hasctrl] let s:AlignPatQty= 1 let ipat = 2 + hasctrl while ipat <= A[0] let s:AlignPat_1 = s:AlignPat_1.'\|'.A[ipat] let ipat = ipat + 1 endwhile let s:AlignPat_1= '\('.s:AlignPat_1.'\)' " call Decho("AlignCtrl<".s:AlignCtrl."> AlignPat<".s:AlignPat_1.">") elseif s:AlignCtrl =~# 'C' "c : cycle through alignment pattern(s) " call Decho("AlignCtrl: cycle through alignment pattern(s)") let s:AlignCtrl = 'C' let s:AlignPatQty= A[0] - hasctrl let ipat = 1 while ipat <= s:AlignPatQty let s:AlignPat_{ipat}= A[(ipat + hasctrl)] " call Decho("AlignCtrl<".s:AlignCtrl."> AlignQty=".s:AlignPatQty." AlignPat_".ipat."<".s:AlignPat_{ipat}.">") let ipat= ipat + 1 endwhile endif endif " Initialize so that begline " is greater than the line's string length -> ragged right. " Have to be careful about visualmode() -- it returns the last visual " mode used whether or not it was used currently. let begcol = virtcol("'<")-1 let endcol = virtcol("'>")-1 if begcol > endcol let begcol = virtcol("'>")-1 let endcol = virtcol("'<")-1 endif " call Decho("begcol=".begcol." endcol=".endcol) let begline = a:firstline let endline = a:lastline if begline > endline let begline = a:lastline let endline = a:firstline endif " Expand range to cover align-able lines when the given range is only the current line. " Look for the first line above the current line that matches the first separator pattern, and " look for the last line below the current line that matches the first separator pattern. if begline == endline " call Decho("case begline == endline") if !exists("s:AlignPat_{1}") echohl Error|echo "(Align) no separators specified!"|echohl None call s:RestoreUserOptions() " call Dret("Align#Align") return endif let seppat = s:AlignPat_{1} let begline= search('^\%(\%('.seppat.'\)\@!.\)*$',"bnW") if begline == 0|let begline= 1|else|let begline= begline + 1|endif let endline= search('^\%(\%('.seppat.'\)\@!.\)*$',"nW") if endline == 0|let endline= line("$")|else|let endline= endline - 1|endif " call Decho("begline=".begline." endline=".endline." curline#".line(".")) endif " call Decho("begline=".begline." endline=".endline) let fieldcnt = 0 if (begline == line("'>") && endline == line("'<")) || (begline == line("'<") && endline == line("'>")) let vmode= visualmode() " call Decho("vmode=".vmode) if vmode == "\" let ragged = ( col("'>") > s:Strlen(getline("'>")) || col("'<") > s:Strlen(getline("'<")) ) else let ragged= 1 endif else let ragged= 1 endif if ragged let begcol= 0 endif " call Decho("lines[".begline.",".endline."] col[".begcol.",".endcol."] ragged=".ragged." AlignCtrl<".s:AlignCtrl.">") " record initial whitespace if s:AlignLeadKeep == 'W' let wskeep = map(getline(begline,endline),"substitute(v:val,'^\\(\\s*\\).\\{-}$','\\1','')") endif " Align needs these options setl et set paste " convert selected range of lines to use spaces instead of tabs " but if first line's initial white spaces are to be retained " then use 'em if begcol <= 0 && s:AlignLeadKeep == 'I' " retain first leading whitespace for all subsequent lines let bgntxt= substitute(getline(begline),'^\(\s*\).\{-}$','\1','') " exception: retain first leading whitespace predicated on g and v patterns " if such a selected line exists if exists("s:AlignGPat") let firstgline= search(s:AlignGPat,"cnW",endline) if firstgline > 0 let bgntxt= substitute(getline(firstgline),'^\(\s*\).\{-}$','\1','') endif elseif exists("s:AlignVPat") let firstvline= search(s:AlignVPat,"cnW",endline) if firstvline > 0 let bgntxt= substitute('^\%(\%('.getline(firstvline).')\@!\)*$','^\(\s*\).\{-}$','\1','') endif endif " call Decho("retaining 1st leading whitespace: bgntxt<".bgntxt.">") let &l:et= s:keep_et endif exe begline.",".endline."ret" " record transformed to spaces leading whitespace if s:AlignLeadKeep == 'W' let wsblanks = map(getline(begline,endline),"substitute(v:val,'^\\(\\s*\\).\\{-}$','\\1','')") endif " Execute two passes " First pass: collect alignment data (max field sizes) " Second pass: perform alignment let pass= 1 while pass <= 2 " call Decho(" ") " call Decho("---- Pass ".pass.": ----") let curline= begline while curline <= endline " Process each line let txt = getline(curline) " call Decho(" ") " call Decho("Pass".pass.": Line ".curline." <".txt.">") " AlignGPat support: allows a selector pattern (akin to g/selector/cmd ) if exists("s:AlignGPat") " call Decho("Pass".pass.": AlignGPat<".s:AlignGPat.">") if match(txt,s:AlignGPat) == -1 " call Decho("Pass".pass.": skipping") let curline= curline + 1 continue endif endif " AlignVPat support: allows a selector pattern (akin to v/selector/cmd ) if exists("s:AlignVPat") " call Decho("Pass".pass.": AlignVPat<".s:AlignVPat.">") if match(txt,s:AlignVPat) != -1 " call Decho("Pass".pass.": skipping") let curline= curline + 1 continue endif endif " Always skip blank lines if match(txt,'^\s*$') != -1 " call Decho("Pass".pass.": skipping") let curline= curline + 1 continue endif " Extract visual-block selected text (init bgntxt, endtxt) let txtlen= s:Strlen(txt) if begcol > 0 " Record text to left of selected area let bgntxt= strpart(txt,0,begcol) " call Decho("Pass".pass.": record text to left: bgntxt<".bgntxt.">") elseif s:AlignLeadKeep == 'W' let bgntxt= substitute(txt,'^\(\s*\).\{-}$','\1','') " call Decho("Pass".pass.": retaining all leading ws: bgntxt<".bgntxt.">") elseif s:AlignLeadKeep == 'w' || !exists("bgntxt") " No beginning text let bgntxt= "" " call Decho("Pass".pass.": no beginning text") endif if ragged let endtxt= "" else " Elide any text lying outside selected columnar region let endtxt= strpart(txt,endcol+1,txtlen-endcol) let txt = strpart(txt,begcol,endcol-begcol+1) endif " call Decho(" ") " call Decho("Pass".pass.": bgntxt<".bgntxt.">") " call Decho("Pass".pass.": txt<". txt .">") " call Decho("Pass".pass.": endtxt<".endtxt.">") if !exists("s:AlignPat_{1}") echohl Error|echo "(Align) no separators specified!"|echohl None call s:RestoreUserOptions() " call Dret("Align#Align") return endif " Initialize for both passes let seppat = s:AlignPat_{1} let ifield = 1 let ipat = 1 let bgnfield = 0 let endfield = 0 let alignstyle = s:AlignStyle let doend = 1 let newtxt = "" let alignprepad = s:AlignPrePad let alignpostpad= s:AlignPostPad let alignsep = s:AlignSep let alignophold = " " let alignop = 'l' " call Decho("Pass".pass.": initial alignstyle<".alignstyle."> seppat<".seppat.">") " Process each field on the line while doend > 0 " C-style: cycle through pattern(s) if s:AlignCtrl == 'C' && doend == 1 let seppat = s:AlignPat_{ipat} " call Decho("Pass".pass.": processing field: AlignCtrl=".s:AlignCtrl." ipat=".ipat." seppat<".seppat.">") let ipat = ipat + 1 if ipat > s:AlignPatQty let ipat = 1 endif endif " cyclic alignment/justification operator handling let alignophold = alignop let alignop = strpart(alignstyle,0,1) if alignop == '+' || doend == 2 let alignop= alignophold else let alignstyle = strpart(alignstyle,1).strpart(alignstyle,0,1) let alignopnxt = strpart(alignstyle,0,1) if alignop == ':' let seppat = '$' let doend = 2 " call Decho("Pass".pass.": alignop<:> case: setting seppat<$> doend==2") endif endif " cyclic separator alignment specification handling let alignsepop= strpart(alignsep,0,1) let alignsep = strpart(alignsep,1).alignsepop " ------------------------------------------------------ " mark end-of-field and the subsequent end-of-separator. " ------------------------------------------------------ let endfield = match(txt,seppat,bgnfield) let sepfield = matchend(txt,seppat,bgnfield) let skipfield= sepfield " call Decho("Pass".pass.": endfield=match(txt<".txt.">,seppat<".seppat.">,bgnfield=".bgnfield.")=".endfield." alignop=".alignop) " Mark eof: Extend field if alignop is '*' and AlignSkip() is true. if alignop == '*' && exists("g:AlignSkip") && type(g:AlignSkip) == 2 " call Decho("Pass".pass.": endfield=match(txt<".txt.">,seppat<".seppat.">,bgnfield=".bgnfield.")=".endfield." alignop=".alignop) " a '*' acts like a '-' while the g:AlignSkip function reference is true except that alignop doesn't advance while g:AlignSkip(curline,endfield) && endfield != -1 let endfield = match(txt,seppat,skipfield) let sepfield = matchend(txt,seppat,skipfield) let skipfield = sepfield " call Decho("Pass".pass.": extend field: endfield<".strpart(txt,bgnfield,endfield-bgnfield)."> alignop<".alignop."> alignstyle<".alignstyle.">") endwhile let alignop = strpart(alignstyle,0,1) let alignstyle= strpart(alignstyle,1).strpart(alignstyle,0,1) " call Decho("Pass".pass.": endfield=match(txt<".txt.">,seppat<".seppat.">,bgnfield=".bgnfield.")=".endfield." alignop=".alignop." (after *)") endif " Mark eof: Extend field if alignop is '-' while alignop == '-' && endfield != -1 let endfield = match(txt,seppat,skipfield) let sepfield = matchend(txt,seppat,skipfield) let skipfield = sepfield let alignop = strpart(alignstyle,0,1) let alignstyle= strpart(alignstyle,1).strpart(alignstyle,0,1) " call Decho("Pass".pass.": extend field: endfield<".strpart(txt,bgnfield,endfield-bgnfield)."> alignop<".alignop."> alignstyle<".alignstyle.">") endwhile let seplen= sepfield - endfield " call Decho("Pass".pass.": seplen=[sepfield=".sepfield."] - [endfield=".endfield."]=".seplen) if endfield != -1 if pass == 1 " --------------------------------------------------------------------- " Pass 1: Update FieldSize to max " call Decho("Pass".pass.": before lead/trail remove: field<".strpart(txt,bgnfield,endfield-bgnfield).">") let field = substitute(strpart(txt,bgnfield,endfield-bgnfield),'^\s*\(.\{-}\)\s*$','\1','') if s:AlignLeadKeep == 'W' let field = bgntxt.field let bgntxt= "" endif let fieldlen= s:Strlen(field) if !exists("FieldSize_{ifield}") let FieldSize_{ifield}= fieldlen " call Decho("Pass".pass.": set FieldSize_{".ifield."}=".FieldSize_{ifield}." <".field."> (init)") elseif fieldlen > FieldSize_{ifield} let FieldSize_{ifield}= fieldlen " call Decho("Pass".pass.": set FieldSize_{".ifield."}=".FieldSize_{ifield}." <".field."> (fieldlen>FieldSize_".ifield.")") endif if !exists("SepSize_{ifield}") let SepSize_{ifield}= seplen " call Decho("Pass".pass.": set SepSize_{".ifield."}=".SepSize_{ifield}." <".field."> (init)") elseif seplen > SepSize_{ifield} let SepSize_{ifield}= seplen " call Decho("Pass".pass.": set SepSize_{".ifield."}=".SepSize_{ifield}." <".field."> (seplen>SepSize_".ifield.")") endif else " --------------------------------------------------------------------- " Pass 2: Perform Alignment let prepad = strpart(alignprepad,0,1) let postpad = strpart(alignpostpad,0,1) let alignprepad = strpart(alignprepad,1).strpart(alignprepad,0,1) let alignpostpad = strpart(alignpostpad,1).strpart(alignpostpad,0,1) let field = substitute(strpart(txt,bgnfield,endfield-bgnfield),'^\s*\(.\{-}\)\s*$','\1','') " call Decho("Pass".pass.": alignprepad <".alignprepad."> prepad =".prepad) " call Decho("Pass".pass.": alignpostpad<".alignpostpad."> postpad=".postpad) if s:AlignLeadKeep == 'W' let field = bgntxt.field let bgntxt= "" endif if doend == 2 let prepad = 0 let postpad= 0 endif let fieldlen = s:Strlen(field) let sep = s:MakeSpace(prepad).strpart(txt,endfield,sepfield-endfield).s:MakeSpace(postpad) " call Decho("Pass".pass.": sep<".sep."> (after prepad, sepfield-endfield,postpad)") if seplen < SepSize_{ifield} if alignsepop == "<" " left-justify separators let sep = sep.s:MakeSpace(SepSize_{ifield}-seplen) " call Decho("Pass".pass.": sep<".sep."> (left-justified)") elseif alignsepop == ">" " right-justify separators let sep = s:MakeSpace(SepSize_{ifield}-seplen).sep " call Decho("Pass".pass.": sep<".sep."> (right-justified)") else " center-justify separators let sepleft = (SepSize_{ifield} - seplen)/2 let sepright = SepSize_{ifield} - seplen - sepleft let sep = s:MakeSpace(sepleft).sep.s:MakeSpace(sepright) " call Decho("Pass".pass.": sep<".sep."> (center-justified)") endif endif let spaces = FieldSize_{ifield} - fieldlen " call Decho("Pass".pass.": spaces=[FieldSize_".ifield."=".FieldSize_{ifield}."] - [fieldlen=".fieldlen."]=".spaces) " call Decho("Pass".pass.": Field #".ifield."<".field."> spaces=".spaces." be[".bgnfield.",".endfield."] pad=".prepad.','.postpad." FS_".ifield."<".FieldSize_{ifield}."> sep<".sep."> ragged=".ragged." doend=".doend." alignop<".alignop.">") " Perform alignment according to alignment style justification if spaces > 0 if alignop == 'c' " center the field let spaceleft = spaces/2 let spaceright= FieldSize_{ifield} - spaceleft - fieldlen let newtxt = newtxt.s:MakeSpace(spaceleft).field.s:MakeSpace(spaceright).sep elseif alignop == 'r' " right justify the field let newtxt= newtxt.s:MakeSpace(spaces).field.sep elseif ragged && doend == 2 " left justify rightmost field (no trailing blanks needed) let newtxt= newtxt.field else " left justfiy the field let newtxt= newtxt.field.s:MakeSpace(spaces).sep endif elseif ragged && doend == 2 " field at maximum field size and no trailing blanks needed let newtxt= newtxt.field else " field is at maximum field size already let newtxt= newtxt.field.sep endif " call Decho("Pass".pass.": newtxt<".newtxt.">") endif " pass 1/2 " bgnfield indexes to end of separator at right of current field " Update field counter let bgnfield= sepfield let ifield = ifield + 1 if doend == 2 let doend= 0 endif " handle end-of-text as end-of-field elseif doend == 1 let seppat = '$' let doend = 2 else let doend = 0 endif " endfield != -1 endwhile " doend loop (as well as regularly separated fields) if pass == 2 " Write altered line to buffer " call Decho("Pass".pass.": bgntxt<".bgntxt."> curline=".curline) " call Decho("Pass".pass.": newtxt<".newtxt.">") " call Decho("Pass".pass.": endtxt<".endtxt.">") keepj call setline(curline,bgntxt.newtxt.endtxt) endif " call Decho("Pass".pass.": line#".curline."<".getline(".")."> (end-of-while)") let curline = curline + 1 endwhile " curline loop let pass= pass + 1 endwhile " pass loop " call Decho("end of two pass loop") " call Decho("ENDWHILE: cursor at (".line(".").",".col(".").") curline#".curline) " restore original leading whitespace if s:AlignLeadKeep == 'W' let iline= begline let i = 0 " call Decho("restore original leading whitespace") while iline <= endline " call Decho("exe ".iline."s/^".wsblanks[i]."/".wskeep[i]."/") exe "keepj ".iline."s/^".wsblanks[i]."/".wskeep[i]."/" let iline= iline + 1 let i = i + 1 endwhile endif if exists("s:DoAlignPop") " AlignCtrl Map support call Align#AlignPop() unlet s:DoAlignPop endif " restore user options and return call s:RestoreUserOptions() " call Dret("Align#Align") return endfun " --------------------------------------------------------------------- " Align#AlignPush: this command/function pushes an alignment control string onto a stack {{{1 fun! Align#AlignPush() " call Dfunc("Align#AlignPush()") " initialize the stack if !exists("s:AlignCtrlStackQty") let s:AlignCtrlStackQty= 1 else let s:AlignCtrlStackQty= s:AlignCtrlStackQty + 1 endif " construct an AlignCtrlStack entry if !exists("s:AlignSep") let s:AlignSep= '' endif let s:AlignCtrlStack_{s:AlignCtrlStackQty}= s:AlignCtrl.'p'.s:AlignPrePad.'P'.s:AlignPostPad.s:AlignLeadKeep.s:AlignStyle.s:AlignSep " call Decho("AlignPush: AlignCtrlStack_".s:AlignCtrlStackQty."<".s:AlignCtrlStack_{s:AlignCtrlStackQty}.">") " push [GV] patterns onto their own stack if exists("s:AlignGPat") let s:AlignGPat_{s:AlignCtrlStackQty}= s:AlignGPat else let s:AlignGPat_{s:AlignCtrlStackQty}= "" endif if exists("s:AlignVPat") let s:AlignVPat_{s:AlignCtrlStackQty}= s:AlignVPat else let s:AlignVPat_{s:AlignCtrlStackQty}= "" endif " call Dret("Align#AlignPush") endfun " --------------------------------------------------------------------- " Align#AlignPop: this command/function pops an alignment pattern from a stack {{{1 " and into the AlignCtrl variables. fun! Align#AlignPop() " call Dfunc("Align#AlignPop()") " sanity checks if !exists("s:AlignCtrlStackQty") echoerr "(AlignPop) AlignPush needs to be used prior to AlignPop" " call Dret("Align#AlignPop <> : AlignPush needs to have been called first") return "" endif if s:AlignCtrlStackQty <= 0 unlet s:AlignCtrlStackQty echoerr "(AlignPop) AlignPush needs to be used prior to AlignPop" " call Dret("Align#AlignPop <> : AlignPop needs to have been called first") return "" endif " pop top of AlignCtrlStack and pass value to AlignCtrl let retval=s:AlignCtrlStack_{s:AlignCtrlStackQty} unlet s:AlignCtrlStack_{s:AlignCtrlStackQty} call Align#AlignCtrl(retval) " pop G pattern stack if s:AlignGPat_{s:AlignCtrlStackQty} != "" call Align#AlignCtrl('g',s:AlignGPat_{s:AlignCtrlStackQty}) else call Align#AlignCtrl('g') endif unlet s:AlignGPat_{s:AlignCtrlStackQty} " pop V pattern stack if s:AlignVPat_{s:AlignCtrlStackQty} != "" call Align#AlignCtrl('v',s:AlignVPat_{s:AlignCtrlStackQty}) else call Align#AlignCtrl('v') endif unlet s:AlignVPat_{s:AlignCtrlStackQty} let s:AlignCtrlStackQty= s:AlignCtrlStackQty - 1 " call Dret("Align#AlignPop <".retval."> : AlignCtrlStackQty=".s:AlignCtrlStackQty) return retval endfun " --------------------------------------------------------------------- " Align#AlignReplaceQuotedSpaces: {{{1 fun! Align#AlignReplaceQuotedSpaces() " call Dfunc("Align#AlignReplaceQuotedSpaces()") let l:line = getline(line(".")) let l:linelen = s:Strlen(l:line) let l:startingPos = 0 let l:startQuotePos = 0 let l:endQuotePos = 0 let l:spacePos = 0 let l:quoteRe = '\\\@, is needed. {{{1 " However, doesn't split at all, so this function returns a list " of arguments which has been: " * split at whitespace " * unless inside "..."s. One may escape characters with a backslash inside double quotes. " along with a leading length-of-list. " " Examples: %Align "\"" will align on "s " %Align " " will align on spaces " " The resulting list: qarglist[0] corresponds to a:0 " qarglist[i] corresponds to a:{i} fun! s:QArgSplitter(qarg) " call Dfunc("s:QArgSplitter(qarg<".a:qarg.">)") if a:qarg =~ '".*"' " handle "..." args, which may include whitespace let qarglist = [] let args = a:qarg " call Decho("handle quoted arguments: args<".args.">") while args != "" let iarg = 0 let arglen = strlen(args) " call Decho(".args[".iarg."]<".args[iarg]."> arglen=".arglen) " find index to first not-escaped '"' " call Decho("find index to first not-escaped \"") while args[iarg] != '"' && iarg < arglen if args[iarg] == '\' let args= strpart(args,1) endif let iarg= iarg + 1 endwhile " call Decho(".args<".args."> iarg=".iarg." arglen=".arglen) if iarg > 0 " handle left of quote or remaining section " call Decho(".handle left of quote or remaining section") if args[iarg] == '"' let qarglist= qarglist + split(strpart(args,0,iarg-1)) else let qarglist= qarglist + split(strpart(args,0,iarg)) endif let args = strpart(args,iarg) let arglen = strlen(args) elseif iarg < arglen && args[0] == '"' " handle "quoted" section " call Decho(".handle quoted section") let iarg= 1 while args[iarg] != '"' && iarg < arglen if args[iarg] == '\' let args= strpart(args,1) endif let iarg= iarg + 1 endwhile " call Decho(".args<".args."> iarg=".iarg." arglen=".arglen) if args[iarg] == '"' call add(qarglist,strpart(args,1,iarg-1)) let args= strpart(args,iarg+1) else let qarglist = qarglist + split(args) let args = "" endif endif " call Decho(".qarglist".string(qarglist)." iarg=".iarg." args<".args.">") endwhile " call Decho("end of loop (handling quoted arguments)") else " split at all whitespace " call Decho("split at all whitespace") let qarglist= split(a:qarg,"[ \t]") endif let qarglistlen= len(qarglist) let qarglist = insert(qarglist,qarglistlen) " call Dret("s:QArgSplitter ".string(qarglist)) return qarglist endfun " --------------------------------------------------------------------- " s:Strlen: this function returns the length of a string, even if its {{{1 " using two-byte etc characters. " Currently, its only used if g:Align_xstrlen is set to a " nonzero value. Solution from Nicolai Weibull, vim docs " (:help strlen()), Tony Mechelynck, and my own invention. fun! s:Strlen(x) " call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen) if type(g:Align_xstrlen) == 1 " allow user to specify a function to compute the string length exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')" elseif g:Align_xstrlen == 1 " number of codepoints (Latin a + combining circumflex is two codepoints) " (comment from TM, solution from NW) let ret= strlen(substitute(a:x,'.','c','g')) elseif g:Align_xstrlen == 2 " number of spacing codepoints (Latin a + combining circumflex is one spacing " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.) " (comment from TM, solution from TM) let ret=strlen(substitute(a:x, '.\Z', 'x', 'g')) elseif g:Align_xstrlen == 3 " virtual length (counting, for instance, tabs as anything between 1 and " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately " preceded by lam, one otherwise, etc.) " (comment from TM, solution from me) let modkeep= &l:mod exe "norm! o\" call setline(line("."),a:x) let ret= virtcol("$") - 1 d keepj norm! k let &l:mod= modkeep else " at least give a decent default if v:version >= 703 let ret= strdisplaywidth(a:x) else let ret= strlen(a:x) endif endif " call Dret("s:Strlen ".ret) return ret endfun " --------------------------------------------------------------------- " s:SaveUserOptions: {{{1 fun! s:SaveUserOptions() " call Dfunc("s:SaveUserOptions() s:saved_user_options=".(exists("s:saved_user_options")? s:saved_user_options : 'n/a')) if !exists("s:saved_user_options") let s:saved_user_options = 1 let s:keep_search = @/ let s:keep_et = &l:et let s:keep_hls = &hls let s:keep_ic = &ic let s:keep_paste = &paste let s:keep_report = &report else let s:saved_user_options = s:saved_user_options + 1 endif " call Dret("s:SaveUserOptions : s:saved_user_options=".s:saved_user_options) endfun " --------------------------------------------------------------------- " s:RestoreUserOptions: {{{1 fun! s:RestoreUserOptions() " call Dfunc("s:RestoreUserOptions() s:saved_user_options=".(exists("s:saved_user_options")? s:saved_user_options : 'n/a')) if exists("s:saved_user_options") && s:saved_user_options == 1 let @/ = s:keep_search let &l:et = s:keep_et let &hls = s:keep_hls let &ic = s:keep_ic let &paste = s:keep_paste let &report = s:keep_report unlet s:keep_search unlet s:keep_et unlet s:keep_hls unlet s:keep_ic unlet s:keep_paste unlet s:keep_report unlet s:saved_user_options elseif exists("s:saved_user_options") let s:saved_user_options= s:saved_user_options - 1 endif " call Dret("s:RestoreUserOptions : s:saved_user_options=".(exists("s:saved_user_options")? s:saved_user_options : 'n/a')) endfun " --------------------------------------------------------------------- " Set up default values: {{{1 "call Decho("-- Begin AlignCtrl Initialization --") call Align#AlignCtrl("default") "call Decho("-- End AlignCtrl Initialization --") " --------------------------------------------------------------------- " Restore: {{{1 let &cpo= s:keepcpo unlet s:keepcpo " vim: ts=4 fdm=marker work/AlignPlugin/autoload/AlignMaps.vim0000664000000000000000000003023414775444730015362 0ustar " AlignMaps.vim : support functions for AlignMaps " Author: Charles E. Campbell " Date: Mar 12, 2013 " Version: 43 " Copyright: Copyright (C) 1999-2012 Charles E. Campbell {{{1 " Permission is hereby granted to use and distribute this code, " with or without modifications, provided that this copyright " notice is copied with it. Like anything else that's free, " Align.vim is provided *as is* and comes with no warranty " of any kind, either expressed or implied. By using this " plugin, you agree that in no event will the copyright " holder be liable for any damages resulting from the use "redraw!|call DechoSep()|call inputsave()|call input("Press to continue")|call inputrestore() " --------------------------------------------------------------------- " Load Once: {{{1 if &cp || exists("g:loaded_AlignMaps") finish endif let g:loaded_AlignMaps= "v43" let s:keepcpo = &cpo set cpo&vim "DechoTabOn " ===================================================================== " Functions: {{{1 " --------------------------------------------------------------------- " AlignMaps#WrapperStart: {{{2 fun! AlignMaps#WrapperStart(vis) range " call Dfunc("AlignMaps#WrapperStart(vis=".a:vis.")") if a:vis keepj norm! ' endif if line("'y") == 0 || line("'z") == 0 || !exists("s:alignmaps_wrapcnt") || s:alignmaps_wrapcnt <= 0 " call Decho("wrapper initialization") let s:alignmaps_wrapcnt = 1 let s:alignmaps_keepgd = &gdefault let s:alignmaps_keepsearch = @/ let s:alignmaps_keepch = &ch let s:alignmaps_keepmy = SaveMark("'y") let s:alignmaps_keepmz = SaveMark("'z") let s:alignmaps_posn = SaveWinPosn(0) " set up fencepost blank lines put ='' keepj norm! mz'a put! ='' ky let s:alignmaps_zline = line("'z") exe "keepj 'y,'zs/@/\177/ge" else " call Decho("embedded wrapper") let s:alignmaps_wrapcnt = s:alignmaps_wrapcnt + 1 keepj norm! 'yjma'zk endif " change some settings to align-standard values set nogd set ch=2 AlignPush keepj norm! 'zk " call Dret("AlignMaps#WrapperStart : alignmaps_wrapcnt=".s:alignmaps_wrapcnt." my=".line("'y")." mz=".line("'z")) endfun " --------------------------------------------------------------------- " AlignMaps#WrapperEnd: {{{2 fun! AlignMaps#WrapperEnd() range " call Dfunc("AlignMaps#WrapperEnd() alignmaps_wrapcnt=".s:alignmaps_wrapcnt." my=".line("'y")." mz=".line("'z")) " remove trailing white space introduced by whatever in the modification zone keepj 'y,'zs/ \+$//e " restore AlignCtrl settings AlignPop let s:alignmaps_wrapcnt= s:alignmaps_wrapcnt - 1 if s:alignmaps_wrapcnt <= 0 " initial wrapper ending exe "keepj 'y,'zs/\177/@/ge" " if the 'z line hasn't moved, then go ahead and restore window position let zstationary= s:alignmaps_zline == line("'z") " remove fencepost blank lines. " restore 'a keepj norm! 'yjmakdd'zdd " restore original 'y, 'z, and window positioning call RestoreMark(s:alignmaps_keepmy) call RestoreMark(s:alignmaps_keepmz) if zstationary > 0 call RestoreWinPosn(s:alignmaps_posn) " call Decho("restored window positioning") endif " restoration of options let &gd= s:alignmaps_keepgd let &ch= s:alignmaps_keepch let @/ = s:alignmaps_keepsearch " remove script variables unlet s:alignmaps_keepch unlet s:alignmaps_keepsearch unlet s:alignmaps_keepmy unlet s:alignmaps_keepmz unlet s:alignmaps_keepgd unlet s:alignmaps_posn endif " call Dret("AlignMaps#WrapperEnd : alignmaps_wrapcnt=".s:alignmaps_wrapcnt." my=".line("'y")." mz=".line("'z")) endfun " --------------------------------------------------------------------- " AlignMaps#MakeMap: make both a normal-mode and a visual mode map for mapname {{{2 fun! AlignMaps#MakeMap(mapname) if exists("g:maplocalleader") let maplead= g:maplocalleader elseif exists("g:mapleader") let maplead= g:mapleader else let maplead= '\' endif exe "nmap ".maplead.a:mapname." AM_".a:mapname exe "vmap ".maplead.a:mapname.' :call AlignMaps#Vis("'.a:mapname.'")'."" endfun " --------------------------------------------------------------------- " AlignMaps#StdAlign: some semi-standard align calls {{{2 fun! AlignMaps#StdAlign(mode) range " call Dfunc("AlignMaps#StdAlign(mode=".a:mode.")") if a:mode == 1 " align on @ " call Decho("align on @") AlignCtrl mIp1P1=l @ 'a,.Align elseif a:mode == 2 " align on @, retaining all initial white space on each line " call Decho("align on @, retaining all initial white space on each line") AlignCtrl mWp1P1=l @ 'a,.Align elseif a:mode == 3 " like mode 2, but ignore /* */-style comments " call Decho("like mode 2, but ignore /* */-style comments") AlignCtrl v ^\s*/[/*] AlignCtrl mWp1P1=l @ 'a,.Align else echoerr "(AlignMaps) AlignMaps#StdAlign doesn't support mode#".a:mode endif " call Dret("AlignMaps#StdAlign") endfun " --------------------------------------------------------------------- " AlignMaps#CharJoiner: joins lines which end in the given character (spaces {{{2 " at end are ignored) fun! AlignMaps#CharJoiner(chr) " call Dfunc("AlignMaps#CharJoiner(chr=".a:chr.")") let aline = line("'a") let rep = line(".") - aline while rep > 0 keepj norm! 'a while match(getline(aline),a:chr . "\s*$") != -1 && rep >= 0 " while = at end-of-line, delete it and join with next keepj norm! 'a$ j! let rep = rep - 1 endwhile " update rep(eat) count let rep = rep - 1 if rep <= 0 " terminate loop if at end-of-block break endif " prepare for next line keepj norm! jma let aline = line("'a") endwhile " call Dret("AlignMaps#CharJoiner") endfun " --------------------------------------------------------------------- " AlignMaps#Equals: supports \t= and \T= {{{2 fun! AlignMaps#Equals() range " call Dfunc("AlignMaps#Equals()") keepj 'a,'zs/\s\+\([.*/+\-%|&\~^]\==\)/ \1/e keepj 'a,'zs@ \+\([.*/+\-%|&\~^]\)=@\1=@ge keepj 'a,'zs/==/\="\\"/ge keepj 'a,'zs/\([!<>:]\)=/\=submatch(1)."\"/ge keepj norm g'zk AlignCtrl mIp1P1=l = AlignCtrl g = keepj 'a,'z-1Align keepj 'a,'z-1s@\([.*/%|&\~^!=]\)\( \+\)=@\2\1=@ge keepj 'a,'z-1s@[^+\-]\zs\([+\-]\)\( \+\)=@\2\1=@ge keepj 'a,'z-1s/\( \+\);/;\1/ge if &ft == "c" || &ft == "cpp" " call Decho("exception for ".&ft) keepj 'a,'z-1v/^\s*\/[*/]/s/\/[*/]/@&@/e keepj 'a,'z-1v/^\s*\/[*/]/s/\*\//@&/e if exists("g:mapleader") exe "keepj norm 'zk" call AlignMaps#StdAlign(1) else exe "keepj norm 'zk" call AlignMaps#StdAlign(1) endif keepj 'y,'zs/^\(\s*\) @/\1/e endif keepj 'a,'z-1s/\%x0f/=/ge keepj 'y,'zs/ @//eg " call Dret("AlignMaps#Equals") endfun " --------------------------------------------------------------------- " AlignMaps#Afnc: useful for splitting one-line function beginnings {{{2 " into one line per argument format fun! AlignMaps#Afnc() " call Dfunc("AlignMaps#Afnc()") " keep display quiet let chkeep = &l:ch let gdkeep = &l:gd let wwkeep = &l:ww let vekeep = &l:ve setlocal ch=2 nogd ve= ww=b,s,<,>,[,] " will use marks y,z ; save current values let mykeep = SaveMark("'y") let mzkeep = SaveMark("'z") " Find beginning of function -- be careful to skip over comments let cmmntid = synIDtrans(hlID("Comment")) let stringid = synIDtrans(hlID("String")) exe "keepj norm! ]]" while search(")","bW") != 0 " call Decho("line=".line(".")." col=".col(".")) let parenid= synIDtrans(synID(line("."),col("."),1)) if parenid != cmmntid && parenid != stringid break endif endwhile keepj norm! %my keepj s/(\s*\(\S\)/(\r \1/e exe "keepj norm! `y%" keepj s/)\s*\(\/[*/]\)/)\r\1/e exe "keepj norm! `y%mz" keepj 'y,'zs/\s\+$//e keepj 'y,'zs/^\s\+//e keepj 'y+1,'zs/^/ / " insert newline after every comma only one parenthesis deep exe "sil! keepj norm! `y\h" let parens = 1 let cmmnt = 0 let cmmntline= -1 while parens >= 1 exe 'keepj norm! ma "ay`a ' " call Decho("parens=".parens." cmmnt=".cmmnt." cmmntline=".cmmntline." line(.)=".line(".")." @a<".@a."> line<".getline(".").">") if @a == "(" let parens= parens + 1 elseif @a == ")" let parens= parens - 1 " comment bypass: /* ... */ or //... elseif cmmnt == 0 && @a == '/' let cmmnt= 1 elseif cmmnt == 1 if @a == '/' let cmmnt = 2 " //... let cmmntline= line(".") elseif @a == '*' let cmmnt= 3 " /*... else let cmmnt= 0 endif elseif cmmnt == 2 && line(".") != cmmntline let cmmnt = 0 let cmmntline= -1 elseif cmmnt == 3 && @a == '*' let cmmnt= 4 elseif cmmnt == 4 if @a == '/' let cmmnt= 0 " ...*/ elseif @a != '*' let cmmnt= 3 endif elseif @a == "," && parens == 1 && cmmnt == 0 exe "keepj norm! i\\" endif endwhile sil! keepj norm! `y%mz% sil! keepj 'y,'zg/^\s*$/d " perform substitutes to mark fields for Align sil! keepj 'y+1,'zv/^\//s/^\s\+\(\S\)/ \1/e sil! keepj 'y+1,'zv/^\//s/\(\S\)\s\+/\1 /eg sil! keepj 'y+1,'zv/^\//s/\* \+/*/ge sil! keepj 'y+1,'zv/^\//s/\w\zs\s*\*/ */ge " func " ws <- declaration -> <-ptr -> <-var-> <-[array][] -> <-glop-> <-end-> sil! keepj 'y+1,'zv/^\//s/^\s*\(\(\K\k*\s*\)\+\)\s\+\([(*]*\)\s*\(\K\k*\)\s*\(\(\[.\{-}]\)*\)\s*\(.\{-}\)\=\s*\([,)]\)\s*$/ \1@#\3@\4\5@\7\8/e sil! keepj 'y+1,'z+1g/^\s*\/[*/]/norm! kJ sil! keepj 'y+1,'z+1s%/[*/]%@&@%ge sil! keepj 'y+1,'z+1s%*/%@&%ge AlignCtrl mIp0P0=l @ sil! keepj 'y+1,'zAlign sil! keepj 'y,'zs%@\(/[*/]\)@%\t\1 %e sil! keepj 'y,'zs%@\*/% */%e sil! keepj 'y,'zs/@\([,)]\)/\1/ sil! keepj 'y,'zs/@/ / AlignCtrl mIlrp0P0= # @ sil! keepj 'y+1,'zAlign sil! keepj 'y+1,'zs/#/ / sil! keepj 'y+1,'zs/@// sil! keepj 'y+1,'zs/\(\s\+\)\([,)]\)/\2\1/e " Restore call RestoreMark(mykeep) call RestoreMark(mzkeep) let &l:ch= chkeep let &l:gd= gdkeep let &l:ww= wwkeep let &l:ve= vekeep " call Dret("AlignMaps#Afnc") endfun " --------------------------------------------------------------------- " AlignMaps#FixMultiDec: converts a type arg,arg,arg; line to multiple lines {{{2 fun! AlignMaps#FixMultiDec() " call Dfunc("AlignMaps#FixMultiDec()") " save register x let xkeep = @x let curline = getline(".") " call Decho("curline<".curline.">") let @x=substitute(curline,'^\(\s*[a-zA-Z_ \t][a-zA-Z0-9<>_ \t]*\)\s\+[(*]*\h.*$','\1','') " call Decho("@x<".@x.">") " transform line exe 'keepj s/,/;\r'.@x.' /ge' "restore register x let @x= xkeep " call Dret("AlignMaps#FixMultiDec : my=".line("'y")." mz=".line("'z")) endfun " --------------------------------------------------------------------- " AlignMaps#AlignMapsClean: this function removes the AlignMaps plugin {{{2 fun! AlignMaps#AlignMapsClean() " call Dfunc("AlignMaps#AlignMapsClean()") for home in split(&rtp,',') + [''] " call Decho("considering home<".home.">") if isdirectory(home) if filereadable(home."/autoload/AlignMaps.vim") " call Decho("deleting ".home."/autoload/AlignMaps.vim") call delete(home."/autoload/AlignMaps.vim") endif if filereadable(home."/plugin/AlignMapsPlugin.vim") " call Decho("deleting ".home."/plugin/AlignMapsPlugin.vim") call delete(home."/plugin/AlignMapsPlugin.vim") endif endif endfor " call Dret("AlignMaps#AlignMapsClean") endfun " --------------------------------------------------------------------- " AlignMaps#Vis: interfaces with visual maps {{{2 fun! AlignMaps#Vis(plugmap) range " call Dfunc("AlignMaps#VisCall(plugmap<".a:plugmap.">) ".a:firstline.",".a:lastline) let amark= SaveMark("a") exe a:firstline ka exe a:lastline if exists("g:maplocalleader") let maplead= g:maplocalleader elseif exists("g:mapleader") let maplead= g:mapleader else let maplead= '\' endif " call Decho("exe norm ".maplead.a:plugmap) exe " norm ".maplead.a:plugmap call RestoreMark(amark) " call Dret("AlignMaps#VisCall") endfun " --------------------------------------------------------------------- " Restore: {{{1 let &cpo= s:keepcpo unlet s:keepcpo " vim: ts=4 fdm=marker work/AlignPlugin/doc/0000775000000000000000000000000014775444730011725 5ustar work/AlignPlugin/doc/Align.txt0000664000000000000000000017546714775444730013544 0ustar *align.txt* The Alignment Tool Jan 07, 2013 Author: Charles E. Campbell (remove NOSPAM from Campbell's email first) Copyright: (c) 2004-2012 by Charles E. Campbell *Align-copyright* The VIM LICENSE applies to Align.vim, AlignMaps.vim, and Align.txt (see |copyright|) except use "Align and AlignMaps" instead of "Vim" NO WARRANTY, EXPRESS OR IMPLIED. USE AT-YOUR-OWN-RISK. ============================================================================== 1. Contents *align* *align-contents* {{{1 1. Contents.................: |align-contents| 2. Alignment Manual.........: |align-manual| 3. Alignment Usage..........: |align-usage| Alignment Concepts.......: |align-concepts| Alignment Commands.......: |align-commands| Alignment Control........: |align-control| Separators.............: |alignctrl-separators| Initial Whitespace.....: |alignctrl-w| |alignctrl-W| |alignctrl-I| Justification..........: |alignctrl-l| |alignctrl-r| |alignctrl-c| Justification Control..: |alignctrl--| |alignctrl-+| |alignctrl-:| Cyclic/Sequential......: |alignctrl-=| |alignctrl-C| Separator Justification: |alignctrl-<| |alignctrl->| |alignctrl-|| Line (de)Selection.....: |alignctrl-g| |alignctrl-v| Temporary Settings.....: |alignctrl-m| Padding................: |alignctrl-p| |alignctrl-P| Current Options........: |alignctrl-settings| |alignctrl-| Alignment Control Init...: |alignctrl-init| Alignment................: |align-align| 4. Alignment Maps...........: |align-maps| \a,....................: |alignmap-a,| \a?....................: |alignmap-a?| \a<....................: |alignmap-a<| \abox..................: |alignmap-abox| \acom..................: |alignmap-acom| \anum..................: |alignmap-anum| \ascom.................: |alignmap-ascom| \adec..................: |alignmap-adec| \adef..................: |alignmap-adef| \afnc..................: |alignmap-afnc| \adcom.................: |alignmap-adcom| \aocom.................: |alignmap-aocom| \tsp...................: |alignmap-tsp| \tsq...................: |alignmap-tsq| \tt....................: |alignmap-tt| \t=....................: |alignmap-t=| \T=....................: |alignmap-T=| \Htd...................: |alignmap-Htd| 5. Alignment Tool History...: |align-history| ============================================================================== 2. Align Manual *alignman* *alignmanual* *align-manual* {{{1 Align comes as a vimball; simply typing > vim Align.vba.gz :so % < should put its components where they belong. The components are: > .vim/plugin/AlignPlugin.vim .vim/plugin/AlignMapsPlugin.vim .vim/plugin/cecutil.vim .vim/autoload/Align.vim .vim/autoload/AlignMaps.vim .vim/doc/Align.txt < To see a user's guide, see |align-userguide| To see examples, see |alignctrl| and |alignmaps| > /=============+=========+=====================================================\ || \ Default/ || || Commands \ Value/ Explanation || || | | || ++==============+====+=======================================================++ || AlignCtrl | | =Clrc-+:pPIWw [..list-of-separator-patterns..] || || | +-------------------------------------------------------+| || | | may be called as a command or as a function: || || | | :AlignCtrl =lp0P0W & \\ || || | | :call Align#AlignCtrl('=lp0P0W','&','\\') || || | | || || | +-------------------------------------------------------++ || 1st arg | = | = all separator patterns are equivalent and are || || | | simultaneously active. Patterns are |regexp|. || || | | C cycle through separator patterns. Patterns are || || | | |regexp| and are active sequentially. || || | | || || | < | < left justify separator Separators are justified, || || | | > right justify separator too. Separator styles || || | | | center separator are cyclic. || || | | || || | l | l left justify Justification styles are always || || | | r right justify cyclic (ie. lrc would mean left j., || || | | c center then right j., then center, repeat. || || | | - skip this separator || || | | + re-use last justification method || || | | : treat rest of text as a field || || | | * use AlignSkip() function (to skip or not) || || | | || || | p1 | p### pad separator on left by # blanks || || | P1 | P### pad separator on right by # blanks || || | | || || | I | I preserve and apply first line's leading white || || | | space to all lines || || | | W preserve leading white space on every line, even || || | | if it varies from line to line || || | | w don't preserve leading white space || || | | || || | | g second argument is a selection pattern -- only || || | | align on lines that have a match (inspired by || || | | :g/selection pattern/command) || || | | v second argument is a selection pattern -- only || || | | align on lines that _don't_ have a match (inspired || || | | by :v/selection pattern/command) || || | | || || | | m Map support: AlignCtrl will immediately do an || || | | AlignPush() and the next call to Align() will do || || | | an AlignPop at the end. This feature allows maps || || | | to preserve user settings. || || | | || || | | default || || | | AlignCtrl default || || | | will clear the AlignCtrl || || | | stack & set the default: AlignCtrl "Ilp1P1=" '=' || || | | || || +----+-------------------------------------------------------+| || More args | More arguments are interpreted as describing separators || || +------------------------------------------------------------+| || No args | AlignCtrl will display its current settings || ||==============+============================================================+| ||[range]Align | [..list-of-separators..] || ||[range]Align! | [AlignCtrl settings] [..list-of-separators..] || || +------------------------------------------------------------+| || | Aligns text over the given range. The range may be || || | selected via visual mode (v, V, or ctrl-v) or via || || | the command line. The Align operation may be invoked || || | as a command or as a function; as a function, the first || || | argument is 0=separators only, 1=AlignCtrl option string || || | followed by a list of separators. || || | :[range]Align || || | :[range]Align [list of separators] || || | :[range]call Align#Align(0) || || | :[range]call Align#Align(0,"list","of","separators",...) || \=============================================================================/ ============================================================================== 3. Alignment Usage *alignusage* *align-usage* *align-userguide* {{{1 ALIGNMENT CONCEPTS *align-concept* *align-concepts* *alignctrl* {{{1 The typical text to be aligned is considered to be: * composed of two or more fields * separated by one or more separator pattern(s): * two or more lines > ws field ws separator ws field ws separator ... ws field ws separator ws field ws separator ... < where "ws" stands for "white space" such as blanks and/or tabs, and "fields" are arbitrary text. For example, consider > x= y= z= 3; xx= yy= zz= 4; zzz= yyy= zzz= 5; a= b= c= 3; < Assume that it is desired to line up all the "=" signs; these, then, are the separators. The fields are composed of all the alphameric text. Assuming they lie on lines 1-4, one may align those "=" signs with: > :AlignCtrl l :1,4Align = < The result is: > x = y = z = 3; xx = yy = zz = 4; zzz = yyy = zzz = 5; a = b = c = 3; < Note how each "=" sign is surrounded by a single space; the default padding is p1P1 (p1 means one space before the separator, and P1 means one space after it). If you wish to change the padding, say, to no padding, use (see |alignctrl-p|) > :AlignCtrl lp0P0 < Next, note how each field is left justified; that's what the "l" in the AlignCtrl parameters (a small letter "ell") does. If right-justification of the fields had been desired, an "r" could've been used: > :AlignCtrl r < yielding > x = y = z = 3; xx = yy = zz = 4; zzz = yyy = zzz = 5; a = b = c = 3; < There are many more options available for field justification: see |alignctrl-c| and |alignctrl--|. Separators, although commonly only one character long, are actually specified by regular expressions (see |regexp|), and one may left justify, right justify, or center them, too (see |alignctrl-<|). Assume that for some reason a left-right-left-right-... justification sequence was desired. This wish is simply achieved with > :AlignCtrl lr :1,4Align = < because the justification commands are considered to be "cyclic"; ie. lr is the same as lrlrlrlrlrlrlr... There's a lot more discussed under |alignctrl|; hopefully the examples there will help, too. ALIGNMENT COMMANDS *align-command* *align-commands* {{{2 The script includes two primary commands and two minor commands: AlignCtrl : this command/function sets up alignment options which persist until changed for later Align calls. It controls such things as: how to specify field separators, initial white space, padding about separators, left/right/center justification, etc. > ex. AlignCtrl wp0P1 Interpretation: during subsequent alignment operations, preserve each line's initial whitespace. Use no padding before separators but provide one padding space after separators. < Align : this command/function operates on the range given it to align text based on one or more separator patterns. The patterns may be provided via AlignCtrl or via Align itself. > ex. :%Align , Interpretation: align all commas over the entire file. < The :Align! format permits alignment control commands to precede the alignment patterns. > ex. :%Align! p2P2 = < This will align all "=" in the file with two padding spaces on both sides of each "=" sign. NOTE ON USING PATTERNS WITH ALIGN:~ Align and AlignCtrl use || to obtain their input patterns and they use an internal function to split arguments at whitespace unless inside "..."s. One may escape characters inside a double-quote string by preceding such characters with a backslash. AlignPush : this command/function pushes the current AlignCtrl state onto an internal stack. > ex. :AlignPush Interpretation: save the current AlignCtrl settings, whatever they may be. They'll also remain as the current settings until AlignCtrl is used to change them. < AlignPop : this command/function pops the current AlignCtrl state from an internal stack. > ex. :AlignPop Interpretation: presumably AlignPush was used (at least once) previously; this command restores the AlignCtrl settings when AlignPush was last used. < Also see |alignctrl-m| for a way to automatically do an AlignPop after an Align (primarily this is for maps). ALIGNMENT OPTIONS *align-option* *align-options* *align-xstrlen* {{{2 *align-utf8* *align-utf* *align-codepoint* *align-strlen* *align-multibyte* For those of you who are using 2-byte (or more) characters such as are available with utf-8, Align now provides a special option which you may choose based upon your needs: Use Built-in strlen() ~ > let g:Align_xstrlen= 0 < This is the fastest method, but it doesn't handle multibyte characters well. It is the default for: enc=latin1 vim compiled without multi-byte support $LANG is en_US.UTF-8 (assuming USA english) Number of codepoints (Latin a + combining circumflex are two codepoints)~ > let g:Align_xstrlen= 1 (default) < Number of spacing codepoints (Latin a + combining circumflex is one~ spacing codepoint; a hard tab is one; wide and narrow CJK are one~ each; etc.)~ > let g:Align_xstrlen= 2 < Virtual length (counting, for instance, tabs as anything between 1 and~ 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when~ immediately preceded by lam, one otherwise, etc.)~ > let g:Align_xstrlen= 3 < User may specify a function to compute the string length~ > let g:Align_xstrlen= "strlen" < This method will cause Align to call upon the named function returning string length. it should resemble the |strlen()| function, taking one argument (the string) for input and returning the string length. By putting one of these settings into your <.vimrc>, Align will use an internal (interpreted) function to determine a string's length instead of Vim's built-in |strlen()| function. Since the function is interpreted, Align will run a bit slower but will handle such strings correctly. The last settings (g:Align_xstrlen= 3 and g:Align_xstrlen="userfuncname") probably will run the slowest but be the most accurate. (thanks to Tony Mechelynck for these) ALIGNMENT CONTROL *:AlignCtrl* *align-control* {{{2 This command doesn't do the alignment operation itself; instead, it controls subsequent alignment operation(s). The first argument to AlignCtrl is a string which may contain one or more alignment control settings. Most of the settings are specified by single letters; the exceptions are the p# and P# commands which interpret a digit following the p or P as specifying padding about the separator. The typical text line is considered to be composed of two or more fields separated by one or more separator pattern(s): > ws field ws separator ws field ws separator ... < where "ws" stands for "white space" such as blanks and/or tabs. SEPARATORS *alignctrl-separators* {{{3 As a result, separators may not have white space (tabs or blanks) on their outsides (ie. ": :" is fine as a separator, but " :: " is not). Usually such separators are not needed, although a map has been provided which works around this limitation and aligns on whitespace (see |alignmap-tsp|). However, if you really need to have separators with leading or trailing whitespace, consider handling them by performing a substitute first (ie. s/ :: /@/g), do the alignment on the temporary pattern (ie. @), and then perform a substitute to revert the separators back to their desired condition (ie. s/@/ :: /g). The Align#Align() function (which is invoked by the :Align command) will first convert tabs over the region into spaces and then apply alignment control. Except for initial white space, white space surrounding the fields is ignored. One has three options just for handling initial white space: --- *alignctrl-w* wWI INITIAL WHITE SPACE *alignctrl-W* {{{3 --- *alignctrl-I* w : ignore all selected lines' initial white space W : retain all selected lines' initial white space I : retain only the first line's initial white space and re-use it for subsequent lines Example: Leading white space options: > +---------------+-------------------+-----------------+ |AlignCtrl w= :=| AlignCtrl W= := | AlignCtrl I= := | +------------------+---------------+-------------------+-----------------+ | Original | w option | W option | I option | +------------------+---------------+-------------------+-----------------+ | a := baaa |a := baaa | a := baaa | a := baaa | | caaaa := deeee |caaaa := deeee | caaaa := deeee | caaaa := deeee| | ee := f |ee := f | ee := f | ee := f | +------------------+---------------+-------------------+-----------------+ < The original has at least one leading white space on every line. Using Align with w eliminated each line's leading white space. Using Align with W preserved each line's leading white space. Using Align with I applied the first line's leading white space (three spaces) to each line. ------ *alignctrl-l* lrc-+: FIELD JUSTIFICATION *alignctrl-r* {{{3 ------ *alignctrl-c* With "lrc", the fields will be left-justified, right-justified, or centered as indicated by the justification specifiers (lrc). The "lrc" options are re-used by cycling through them as needed: l means llllll.... r means rrrrrr.... lr means lrlrlr.... llr means llrllr.... Example: Justification options: Align = > +------------+-------------------+-------------------+-------------------+ | Original | AlignCtrl l | AlignCtrl r | AlignCtrl lr | +------------+-------------------+-------------------+-------------------+ | a=bb=ccc=1 |a = bb = ccc = 1| a = bb = ccc = 1|a = bb = ccc = 1| | ccc=a=bb=2 |ccc = a = bb = 2|ccc = a = bb = 2|ccc = a = bb = 2| | dd=eee=f=3 |dd = eee = f = 3| dd = eee = f = 3|dd = eee = f = 3| +------------+-------------------+-------------------+-------------------+ | Alignment |l l l l| r r r r|l r l r| +------------+-------------------+-------------------+-------------------+ < AlignCtrl l : The = separator is repeatedly re-used, as the cycle only consists of one character (the "l"). Every time left-justification is used for fields. AlignCtrl r : The = separator is repeatedly re-used, as the cycle only consists of one character (the "r"). Every time right-justification is used for fields AlignCtrl lr: Again, the "=" separator is repeatedly re-used, but the fields are justified alternately between left and right. Even more separator control is available! With "-+:": - : skip treating the separator as a separator. *alignctrl--* + : repeat use of the last "lrc" justification *alignctrl-+* : : treat the rest of the line as a single field *alignctrl-:* * : like -, but only if g:AlignSkip() returns true *alignctrl-star* (see |alignctrl-alignskip|) Example: More justification options: Align = > +------------+---------------+--------------------+---------------+ | Original | AlignCtrl -l | AlignCtrl rl+ | AlignCtrl l: | +------------+---------------+--------------------+---------------+ | a=bb=ccc=1 |a=bb = ccc=1 | a = bb = ccc = 1 |a = bb=ccc=1 | | ccc=a=bb=2 |ccc=a = bb=2 |ccc = a = bb = 2 |ccc = a=bb=2 | | dd=eee=f=3 |dd=eee = f=3 | dd = eee = f = 3 |dd = eee=f=3 | +------------+---------------+--------------------+---------------+ | Alignment |l l | r l l l |l l | +------------+---------------+--------------------+---------------+ < In the first example in "More justification options": The first "=" separator is skipped by the "-" specification, and so "a=bb", "ccc=a", and "dd=eee" are considered as single fields. The next "=" separator has its (left side) field left-justified. Due to the cyclic nature of separator patterns, the "-l" specification is equivalent to "-l-l-l ...". Hence the next specification is a "skip", so "ccc=1", etc are fields. In the second example in "More justification options": The first field is right-justified, the second field is left justified, and all remaining fields repeat the last justification command (ie. they are left justified, too). Hence rl+ is equivalent to rlllllllll ... (whereas plain rl is equivalent to rlrlrlrlrl ... ). In the third example in "More justification options": The text following the first separator is treated as a single field. Thus using the - and : operators one can apply justification to a single separator. ex. 1st separator only: AlignCtrl l: 2nd separator only: AlignCtrl -l: 3rd separator only: AlignCtrl --l: etc. *g:AlignSkip* Align Skip Control *alignctrl-alignskip* The separator control '*' permits a function to decide whether or not a character which matches the current separator pattern should instead be skipped. 1. Define a function; example: > fun! AlignSkipString(lineno,indx) let synid = synID(a:lineno,a:indx+1,1) let synname = synIDattr(synIDtrans(synid),"name") let ret= (synname == "String")? 1 : 0 return ret endfun < Input: lineno: current line number indx : index to character; leftmost character in the line has an indx of 0 (like |strpart()|) Output: 0 : if separator is ok 1 : skip separator like it was a '-' 2. Set up |g:AlignSkip| as a function reference (see |Funcref|): > let g:AlignSkip= function("AlignSkipString") < 3. Use * as a separator control where a separator potentially should be skipped over. --- *alignctrl-=* =C CYCLIC VS ALL-ACTIVE SEPARATORS *alignctrl-C* {{{3 --- The separators themselves may be considered as equivalent and simultaneously active ("=") or sequentially cycled through ("C"). Separators are regular expressions (|regexp|) and are specified as the second, third, etc arguments. When the separator patterns are equivalent and simultaneously active, there will be one pattern constructed: > AlignCtrl ... pat1 pat2 pat3 < becomes > \(pat1\|pat2\|pat3\) < (ie. pat1 -or- pat2 -or- pat3; see |/bar|) Each separator pattern is thus equivalent and simultaneously active. The cyclic separator AlignCtrl option stores a list of patterns, only one of which is active for each field at a time. Example: Equivalent/Simultaneously-Active vs Cyclic Separators > +-------------+------------------+---------------------+----------------------+ | Original | AlignCtrl = = + -| AlignCtrl = = | AlignCtrl C = + - | +-------------+------------------+---------------------+----------------------+ |a = b + c - d|a = b + c - d |a = b + c - d |a = b + c - d | |x = y = z + 2|x = y = z + 2 |x = y = z + 2|x = y = z + 2 | |w = s - t = 0|w = s - t = 0 |w = s - t = 0 |w = s - t = 0 | +-------------+------------------+---------------------+----------------------+ < The original is initially aligned with all operators (=+-) being considered as equivalent and simultaneously active field separators. Thus the "AlignCtrl = = + -" example shows no change. The second example only accepts the '=' as a field separator; consequently "b + c - d" is now a single field. The third example illustrates cyclic field separators and is analyzed in the following illustration: > field1 separator field2 separator field3 separator field4 a = b + c - d x = y = z + 2 w = s - t = 0 < The word "cyclic" is used because the patterns form a cycle of use; in the above case, its = + - = + - = + - = + -... Example: Cyclic separators > Label : this is some text discussing ":"s | ex. abc:def:ghi Label : this is some text with a ":" in it | ex. abc:def < apply AlignCtrl lWC : | | (select lines)Align > Label : this is some text discussing ":"s | ex. abc:def:ghi Label : this is some text with a ":" in it | ex. abcd:efg < In the current example, : is the first separator So the first ":"s are aligned | is the second separator but subsequent ":"s are not. | is the third separator The "|"s are aligned, too. : is the fourth separator Since there aren't two bars, | is the fifth separator the subsequent potential cycles | is the sixth separator don't appear. ... In this case it would probably have been a better idea to have used > AlignCtrl WCl: : | < as that alignment control would guarantee that no more cycling would be used after the vertical bar. Example: Cyclic separators Original: > a| b&c | (d|e) & f-g-h aa| bb&cc | (dd|ee) & ff-gg-hh aaa| bbb&ccc | (ddd|eee) & fff-ggg-hhh < AlignCtrl C | | & - > a | b&c | (d|e) & f - g-h aa | bb&cc | (dd|ee) & ff - gg-hh aaa | bbb&ccc | (ddd|eee) & fff - ggg-hhh < In this example, the first and second separators are "|", the third separator is "&", and the fourth separator is "-", (cycling) the fifth and sixth separators are "|", the seventh separator is "&", and the eighth separator is "-", etc. Thus the first "&"s are (not yet) separators, and hence are treated as part of the field. Ignoring white space for the moment, the AlignCtrl shown here means that Align will work with > field | field | field & field - field | field | field & field - ... < --- *alignctrl-<* <>| SEPARATOR JUSTIFICATION *alignctrl->* {{{3 --- *alignctrl-|* Separators may be of differing lengths as shown in the example below. Hence they too may be justified left, right, or centered. Furthermore, separator justification specifications are cyclic: < means <<<<<... justify separator(s) to the left > means >>>>>... justify separator(s) to the right | means |||||... center separator(s) Example: Separator Justification: Align -\+ > +-----------------+ | Original | +-----------------+ | a - bbb - c | | aa -- bb -- ccc | | aaa --- b --- cc| +---------------------+-+-----------------+-+---------------------+ | AlignCtrl < | AlignCtrl > | AlignCtrl | | +---------------------+---------------------+---------------------+ | a - bbb - c | a - bbb - c | a - bbb - c | | aa -- bb -- ccc | aa -- bb -- ccc | aa -- bb -- ccc | | aaa --- b --- cc | aaa --- b --- cc | aaa --- b --- cc | +---------------------+---------------------+---------------------+ < --- *alignctrl-g* gv SELECTIVE APPLICATION *alignctrl-v* {{{3 --- These two options provide a way to select (g) or to deselect (v) lines based on a pattern. Ideally :g/pat/Align would work; unfortunately it results in Align#Align() being called on each line satisfying the pattern separately. > AlignCtrl g pattern < Align will only consider those lines which have the given pattern. > AlignCtrl v pattern < Align will only consider those lines without the given pattern. As an example of use, consider the following example: > :AlignCtrl v ^\s*/\* Original :Align = :Align = +----------------+------------------+----------------+ |one= 2; |one = 2; |one = 2; | |three= 4; |three = 4; |three = 4; | |/* skip=this */ |/* skip = this */ |/* skip=this */ | |five= 6; |five = 6; |five = 6; | +----------------+------------------+----------------+ < The first "Align =" aligned with all "="s, including the one in the "/* skip=this */" comment. The second "Align =" had a AlignCtrl v-pattern which caused it to skip (ignore) the "/* skip=this */" line when aligning. To remove AlignCtrl's g and v patterns, use (as appropriate) > AlignCtrl g AlignCtrl v < To see what g/v patterns are currently active, just use the reporting capability of an unadorned call to AlignCtrl: > AlignCtrl < --- m MAP SUPPORT *alignctrl-m* {{{3 --- This option primarily supports the development of maps. The Align#AlignCtrl() call will first do an Align#AlignPush() (ie. retain current alignment control settings). The next Align#Align() will, in addition to its alignment job, finish up with an Align#AlignPop(). Thus the Align#AlignCtrl settings that follow the "m" are only temporarily in effect for just the next Align#Align(). --- p### *alignctrl-p* P### PADDING *alignctrl-P* {{{3 --- These two options control pre-padding and post-padding with blanks about the separator. One may pad separators with zero to nine spaces; the padding number(s) is/are treated as a cyclic parameter. Thus one may specify padding separately for each field or re-use a padding pattern. > Example: AlignCtrl p102P0 +---------+----------------------------------+ | Original| a=b=c=d=e=f=g=h=1 | | Align = | a =b=c =d =e=f =g =h=1 | +---------+----------------------------------+ | prepad | 1 0 2 1 0 2 1 0 | +---------+----------------------------------+ < This example will cause Align to: pre-pad the first "=" with a single blank, pre-pad the second "=" with no blanks, pre-pad the third "=" with two blanks, pre-pad the fourth "=" with a single blank, pre-pad the fifth "=" with no blanks, pre-pad the sixth "=" with two blanks, etc. --------------- *alignctrl-settings* No option given DISPLAY STATUS *alignctrl-* {{{3 --------------- *alignctrl-no-option* AlignCtrl, when called with no arguments, will display the current alignment control settings. A typical display is shown below: > AlignCtrl<=> qty=1 AlignStyle Padding<1|1> Pat1<\(=\)> < Interpreting, this means that the separator patterns are all equivalent; in this case, there's only one (qty=1). Fields will be padded on the right with spaces (left justification), and separators will be padded on each side with a single space. To change one of these items, see: AlignCtrl......|alignctrl| qty............|align-concept| AlignStyle.....|alignctrl--| |alignctrl-+| |alignctrl-:| |alignctrl-c| Padding........|alignctrl-p| |alignctrl-P| One may get a string which can be fed back into AlignCtrl: > :let alignctrl= Align#AlignCtrl() < This form will put a string describing the current AlignCtrl options, except for the "g" and "v" patterns, into a variable. The Align#AlignCtrl() function will still echo its settings, however. One can feed any non-supported "option" to AlignCtrl() to prevent this, however: > :let alignctrl= Align#AlignCtrl("d") ALIGNMENT CONTROL INITIALIZATION *alignctrl-init* *alignctrl-initialization* {{{2 If you'd like to have your own default AlignCtrl, you'll be wanting to put it in a file such as: > $HOME/.vim/after/plugin/AlignPlugin.vim < Anything in that file would be sourced at startup, but after your .vimrc and after $HOME/.vim/plugin/AlignPlugin.vim; hence, :Align and :AlignCtrl will then be defined. ALIGNMENT *:Align* *align-align* {{{2 Once the alignment control has been determined, the user specifies a range of lines for the Align command/function to do its thing. Alignment is often done on a line-range basis, but one may also restrict alignment to a visual block using ctrl-v. For any visual mode, one types the colon (:) and then "Align". One may, of course, specify a range of lines: > :[range]Align [list-of-separators] < where the |:range| is the usual Vim-powered set of possibilities; the list of separators is the same as the AlignCtrl capability. There is only one list of separators, but either AlignCtrl or Align can be used to specify that list. An alternative form of the Align command can handle both alignment control and the separator list: > :[range]Align! [alignment-control-string] [list-of-separators] < The alignment control string will be applied only for this particular application of Align (it uses |alignctrl-m|). The "g pattern" and "v pattern" alignment controls (see |alignctrl-g| and |alignctrl-v|) are also available via this form of the Align command. Align makes two passes over the text to be aligned. The first pass determines how many fields there are and determines the maximum sizes of each field; these sizes are then stored in a vector. The second pass pads the field (left/right/centered as specified) to bring its length up to the maximum size of the field. Then the separator and its AlignCtrl-specified padding is appended. Pseudo-Code:~ During pass 1 | For all fields in the current line || Determine current separator || Examine field specified by current separator || Determine length of field and save if largest thus far Initialize newline based on initial whitespace option (wWI) During pass 2 | For all fields in current line || Determine current separator || Extract field specified by current separator || Prepend/append padding as specified by AlignCtrl || (right/left/center)-justify to fit field into max-size field || Append separator with AlignCtrl-specified separator padding || Delete current line, install newly aligned line The g and v AlignCtrl patterns cause the passes not to consider lines for alignment, either by requiring that the g-pattern be present or that the v-pattern not be present. The whitespace on either side of a separator is ignored. ============================================================================== 4. Alignment Maps *alignmaps* *align-maps* {{{1 There are a number of maps provided in the AlignMaps plugin which depend upon the Align plugin. The maps provided by AlignMaps typically start with a leading "t" (for the older "textab" program which Align supercedes) or with an "a" for the more complicated alignment maps. The AlignMaps plugin, although provided in the vimball containing Align.vim, is really a separate plugin (Align doesn't depend on AlignMaps). Consequently, if you'd rather not have AlignMaps's mappings, just use the *:AlignMapsClean* command to remove its components. The :AlignMapsClean command does not remove any maps generated by AlignMaps in the current instance of vim. The maps are shown below with a leading backslash (\). However, the actual maps use the construct (see |mapleader|), so the maps' leading kick-off character is easily customized. Furthermore, all the maps specified by the AlignMaps plugin use the construct (see ||and |usr_41.txt|). Hence, if one wishes to override the mapping(s) entirely, one may do that, too. As an example: > map ACOM AM_acom < would have \ACOM do what \acom previously did (assuming that the mapleader has been left at its default value of a backslash). \a, : useful for breaking up comma-separated declarations prior to \adec |alignmap-a,| \a( : aligns ( and , (useful for prototypes) *alignmap-a(* \a? : aligns (...)? ...:... expressions on ? and : |alignmap-a?| \a< : aligns << and >> for c++ |alignmap-a<| \a= : aligns := assignments |alignmap-a=| \abox : draw a C-style comment box around text lines |alignmap-abox| \acom : useful for aligning comments |alignmap-acom| \adcom: useful for aligning comments in declarations |alignmap-adcom| \anum : useful for aligning numbers |alignmap-anum| NOTE: For the visual-mode use of \anum, is needed! See http://www.drchip.org/astronaut/vim/index.html#VIS \aenum: align a European-style number |alignmap-anum| \aunum: align a USA-style number |alignmap-anum| \adec : useful for aligning declarations |alignmap-adec| \adef : useful for aligning definitions |alignmap-adef| \afnc : useful for aligning ansi-c style functions' argument lists |alignmap-afnc| \adcom: a variant of \acom, restricted to comment |alignmap-adcom| containing lines only, but also only for those which don't begin with a comment. Good for certain declaration styles. \aocom: a variant of \acom, restricted to comment |alignmap-aocom| containing lines only \tab : align a table based on tabs *alignmap-tab* (converts to spaces) \tml : useful for aligning the trailing backslashes |alignmap-tml| used to continue lines (shell programming, etc) \tsp : use Align to make a table separated by blanks |alignmap-tsp| (left justified) \ts, : like \t, but swaps whitespace on the right of *alignmap-ts,* the commas to their left \ts: : like \t: but swaps whitespace on the right of *alignmap-ts:* the colons to their left \ts< : like \t< but swaps whitespace on the right of *alignmap-ts<* the less-than signs to their left \ts= : like \t= but swaps whitespace on the right of *alignmap-ts=* the equals signs to their left \Tsp : use Align to make a table separated by blanks |alignmap-Tsp| (right justified) \tsq : use Align to make a table separated by blanks |alignmap-tsq| (left justified) -- "strings" are not split up \tt : useful for aligning LaTeX tabular tables |alignmap-tt| \Htd : tabularizes html tables: |alignmap-Htd| ...field... ...field... *alignmap-t|* *alignmap-t#* *alignmap-t,* *alignmap-t:* *alignmap-t;* *alignmap-t<* *alignmap-t?* *alignmap-t~* *alignmap-m=* \tx : make a left-justified alignment on character "x" where "x" is: ,:<=@|# |alignmap-t=| \Tx : make a right-justified alignment on character "x" where "x" is: ,:<=@# |alignmap-T=| \m= : like \t= but aligns with %... style comments The leading backslash is actually (see |mapleader| to learn how to customize the leader to be whatever you like). These maps use the package and are defined in the file. Although the maps use AlignCtrl options, they typically use the "m" option which pushes the options (AlignPush). The associated Align call which follows will then AlignPop the user's original options back. ALIGNMENT MAP USE WITH MARK AND MOVE~ In the examples below, one may select the text with a "ma" at the first line, move to the last line, then execute the map. ALIGNMENT MAP USE WITH VISUAL MODE~ Alternatively, one may select the text with the "V" visual mode command. If you want to use visual-block mode (ctrl-v), I suggest using an AlignMap with the vis.vim plugin, available at either stable: http://vim.sourceforge.net/scripts/script.php?script_id=1195 devel : http://www.drchip.org/astronaut/vim/index.html#VIS Use it with commands such as > ctrl-v (move) :B norm \alignmap_sequence < ALIGNMENT MAP USE WITH MENUS~ One may use the mark-and-move style (ma, move, use the menu) or the visual mode style (use the V visual mode, move, then select the alignment map with menu selection). The alignment map menu items are under DrChip.AlignMaps . One may even change the top level menu name to whatever is wished; by default, its > let g:DrChipTopLvlMenu= "DrChip." < If you set the variable to the empty string (""), then no menu items will be produced. Of course, one must have a vim with +menu, the gui must be running, and |'go'| must have the menu bar suboption (ie. m must be included). COMPLEX ALIGNMENT MAP METHOD~ For those complex alignment maps which do alignment on constructs (e.g. \acom, \adec, etc), a series of substitutes is used to insert "@" symbols in appropriate locations. Align#Align() is then used to do alignment directly on "@"s; then it is followed by further substitutes to do clean-up. However, the maps \WS and \WE, used by every map supported by AlignMaps, protect any original embedded "@" symbols by first converting them to characters, doing the requested job, and then converting them back. > \WS calls AlignMaps#WrapperStart() \WE calls AlignMaps#WrapperEnd() < --------------------------- Alignment Map Examples: \a, *alignmap-a,* {{{3 --------------------------- Original: illustrates comma-separated declaration splitting: > int a,b,c; struct ABC_str abc,def; < Becomes: > int a; int b; int c; struct ABC_str abc; struct ABC_str def; < --------------------------- Alignment Map Examples: \a? *alignmap-a?* {{{3 --------------------------- Original: illustrates ()?: aligning > printf("<%s>\n", (x == ABC)? "abc" : (x == DEFG)? "defg" : (x == HIJKL)? "hijkl" : "???"); < Becomes: select "(x == ..." lines, then \a? > printf("<%s>\n", (x == ABC)? "abc" : (x == DEFG)? "defg" : (x == HIJKL)? "hijkl" : "???"); < --------------------------- Alignment Map Examples: \a< *alignmap-a<* {{{3 --------------------------- Original: illustrating aligning of << and >> > cin << x; cin << y; cout << "this is x=" << x; cout << "but y=" << y << "is not"; < Becomes: select "(x == ..." lines, then \a< > cin << x; cin << y; cout << "this is x=" << x; cout << "but y=" << y << "is not"; < --------------------------- Alignment Map Examples: \a= *alignmap-a=* {{{3 --------------------------- Original: illustrates how to align := assignments > aa:=bb:=cc:=1; a:=b:=c:=1; aaa:=bbb:=ccc:=1; < Bcomes: select the three assignment lines, then \a:= > aa := bb := cc := 1; a := b := c := 1; aaa := bbb := ccc := 1; < --------------------------- Alignment Map Examples: \abox *alignmap-abox* {{{3 --------------------------- Original: illustrates how to comment-box some text > This is some plain text which will soon be surrounded by a comment box. < Becomes: Select "This..box." with ctrl-v, press \abox > /*************************** * This is some plain text * * which will * * soon be surrounded by a * * comment box. * ***************************/ < --------------------------- Alignment Map Examples: \acom *alignmap-acom* {{{3 --------------------------- Original: illustrates aligning C-style comments (works for //, too) > if(itworks) { /* this */ then= dothis; /* is a */ } /* set of three comments */ < Becomes: Select the three lines, press \acom > if(itworks) { /* this */ then= dothis; /* is a */ } /* set of three comments */ < Also see |alignmap-aocom| --------------------------- Alignment Map Examples: \anum *alignmap-anum* {{{3 --------------------------- First, note that the behavior of the \anum map depends on the existence of either the vim variable > g:alignmaps_usanumber < or > g:alignmaps_euronumber < when AlignMaps is loaded. Essentially, "usa" numbers use "."s and "euro" numbers use ","s to separate the integer from the fractional portion of a number. "Usa" numbers are default. Original: illustrates how to get numbers lined up > -1.234 .5678 -.901e-4 1.234 5.678 9.01e-4 12.34 56.78 90.1e-4 123.4 567.8 901.e-4 < Becomes: Go to first line, ma. Go to last line, press \anum > -1.234 .5678 -.901e-4 1.234 5.678 9.01e-4 12.34 56.78 90.1e-4 123.4 567.8 901.e-4 < Original: > | -1.234 .5678 -.901e-4 | | 1.234 5.678 9.01e-4 | | 12.34 56.78 90.1e-4 | | 123.4 567.8 901.e-4 | < Becomes: Select the numbers with ctrl-v (visual-block mode), > press \anum | -1.234 .5678 -.901e-4 | | 1.234 5.678 9.01e-4 | | 12.34 56.78 90.1e-4 | | 123.4 567.8 901.e-4 | < Original: > -1,234 ,5678 -,901e-4 1,234 5,678 9,01e-4 12,34 56,78 90,1e-4 123,4 567,8 901,e-4 < Becomes: (assuming g:alignmaps_euronumber exists) Go to first line, ma. Go to last line, press \anum > -1,234 ,5678 -,901e-4 1,234 5,678 9,01e-4 12,34 56,78 90,1e-4 123,4 567,8 901,e-4 < In addition: \aenum is provided to support European-style numbers \aunum is provided to support USA-style numbers *g:alignmaps_usanumber* *g:alignmaps_euronumber* One may get \aenum behavior for \anum by putting > let g:alignmaps_euronumber= 1 < or \aunum behavior for \anum by putting > let g:alignmaps_usanumber= 1 < in one's <.vimrc>. --------------------------- Alignment Map Examples: \ascom *alignmap-ascom* {{{3 --------------------------- Original: > /* A Title */ int x; /* this is a comment */ int yzw; /* this is another comment*/ < Becomes: Select the three lines, press \ascom > /* A Title */ int x; /* this is a comment */ int yzw; /* this is another comment */ < --------------------------- Alignment Map Examples: \adec *alignmap-adec* {{{3 --------------------------- Original: illustrates how to clean up C/C++ declarations > int a; float b; double *c=NULL; char x[5]; struct abc_str abc; struct abc_str *pabc; int a; /* a */ float b; /* b */ double *c=NULL; /* b */ char x[5]; /* x[5] */ struct abc_str abc; /* abc */ struct abc_str *pabc; /* pabc */ static int a; /* a */ static float b; /* b */ static double *c=NULL; /* b */ static char x[5]; /* x[5] */ static struct abc_str abc; /* abc */ static struct abc_str *pabc; /* pabc */ < Becomes: Select the declarations text, then \adec > int a; float b; double *c = NULL; char x[5]; struct abc_str abc; struct abc_str *pabc; int a; /* a */ float b; /* b */ double *c = NULL; /* b */ char x[5]; /* x[5] */ struct abc_str abc; /* abc */ struct abc_str *pabc; /* pabc */ static int a; /* a */ static float b; /* b */ static double *c = NULL; /* b */ static char x[5]; /* x[5] */ static struct abc_str abc; /* abc */ static struct abc_str *pabc; /* pabc */ < --------------------------- Alignment Map Examples: \adef *alignmap-adef* {{{3 --------------------------- Original: illustrates how to line up #def'initions > #define ONE 1 #define TWO 22 #define THREE 333 #define FOUR 4444 < Becomes: Select four definition lines, apply \adef > # define ONE 1 # define TWO 22 # define THREE 333 # define FOUR 4444 < --------------------------- Alignment Map Examples: \afnc *alignmap-afnc* {{{3 --------------------------- This map is an exception to the usual selection rules. It uses "]]" to find the function body's leading "{". Just put the cursor anywhere in the function arguments and the entire function declaration should be processed. Because "]]" looks for that "{" in the first column, the "original" and "becomes" examples are in the first column, too. Original: illustrates lining up ansi-c style function definitions > int f( struct abc_str ***a, /* one */ long *b, /* two */ int c) /* three */ { } < Becomes: put cursor anywhere before the '{', press \afnc > int f( struct abc_str ***a, /* one */ long *b, /* two */ int c) /* three */ { } < --------------------------- Alignment Map Examples: \adcom *alignmap-adcom* {{{3 --------------------------- Original: illustrates aligning comments that don't begin lines (optionally after some whitespace). > struct { /* this is a test */ int x; /* of how */ double y; /* to use adcom */ }; < Becomes: Select the inside lines of the structure, then press \adcom. The comment-only line is ignored but the other two comments get aligned. > struct { /* this is a test */ int x; /* of how */ double y; /* to use adcom */ }; < --------------------------- Alignment Map Examples: \aocom *alignmap-aocom* {{{3 --------------------------- Original: illustrates how to align C-style comments (works for //, too) but restricted only to aligning with those lines containing comments. See the difference from \acom (|alignmap-acom|). > if(itworks) { /* this comment */ then= dothis; } /* only appears on two lines */ < Becomes: Select the three lines, press \aocom > if(itworks) { /* this comment */ then= dothis; } /* only appears on two lines */ < Also see |alignmap-acom| --------------------------- *alignmap-Tsp* Alignment Map Examples: \tsp *alignmap-tsp* {{{3 --------------------------- Normally Align can't use white spaces for field separators as such characters are ignored surrounding field separators. The \tsp and \Tsp maps get around this limitation. Original: > one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen < Becomes: Select the lines, \tsp > one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen < Becomes: Select the lines, \Tsp > one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen < --------------------------- Alignment Map Examples: \tsq *alignmap-tsq* {{{3 --------------------------- The \tsp map is useful for aligning tables based on white space, but sometimes one wants double-quoted strings to act as a single object in spite of embedded spaces. The \tsq map was invented to support this. (thanks to Leif Wickland) Original: > "one two" three four "five six" < Becomes: Select the lines, \tsq > "one two" three four "five six" < --------------------------- Alignment Map Examples: \tt *alignmap-tt* {{{3 --------------------------- Original: illustrates aligning a LaTex Table > \begin{tabular}{||c|l|r||} \hline\hline one&two&three\\ \hline four&five&six\\ seven&eight&nine\\ \hline\hline \end{tabular} < Becomes: Select the three lines inside the table > (ie. one..,four..,seven..) and press \tt \begin{tabular}{||c|l|r||} \hline\hline one & two & three \\ \hline four & five & six \\ seven & eight & nine \\ \hline\hline \end{tabular} < ---------------------------- Alignment Map Examples: \tml *alignmap-tml* {{{3 ---------------------------- Original: illustrates aligning multi-line continuation marks > one \ two three \ four five six \ seven \\ \ eight \nine \ ten \ < Becomes: > one \ two three \ four five six \ seven \\ \ eight \nine \ ten \ < --------------------------- Alignment Map Examples: \t= *alignmap-t=* {{{3 --------------------------- Original: illustrates left-justified aligning of = > aa=bb=cc=1;/*one*/ a=b=c=1;/*two*/ aaa=bbb=ccc=1;/*three*/ < Becomes: Select the three equations, press \t= > aa = bb = cc = 1; /* one */ a = b = c = 1; /* two */ aaa = bbb = ccc = 1; /* three */ < --------------------------- Alignment Map Examples: \T= *alignmap-T=* {{{3 --------------------------- Original: illustrates right-justified aligning of = > aa=bb=cc=1; /* one */ a=b=c=1; /* two */ aaa=bbb=ccc=1; /* three */ < Becomes: Select the three equations, press \T= > aa = bb = cc = 1; /* one */ a = b = c = 1; /* two */ aaa = bbb = ccc = 1; /* three */ < --------------------------- Alignment Map Examples: \Htd *alignmap-Htd* {{{3 --------------------------- Original: for aligning tables with html > ...field one......field two... ...field three......field four... < Becomes: Select ... lines, press \Htd > ...field one... ...field two... ...field three... ...field four... < ============================================================================== 4. Alignment Tools' History *align-history* {{{1 ALIGN HISTORY {{{2 v37 Nov 29, 2012 * (Kim Jang-hwan) reported that with g:Align_xstrlen set to 3 that the cursor was moved (linewise) after invocation. Fixed. Jan 07, 2013 * now has visual mode mappings to accompany all normal mode mappings (use |V| to invoke) v36 May 20, 2009 * Previously, the "W" AlignCtrl setting, intended to retain initial white space, did so by convert- ing any leading tabs into an equivalent quantity of blanks (using the current tabstop setting). Align will now retain leading tabs. Nov 24, 2009 * QArgSplitter() used split(), intending to split on white space only. However, the \tab map uses ctrl-o as a separator instead of tabs; the split() function treated the ctrl-o as a whitespace character, too. Solution: give split() an explicit pattern matching blanks and tabs, only. \tab now works again! Jun 29, 2010 * included |g:AlignSkip| and |alignctrl-star| support May 10, 2011 * if the range is only one line, then Align will automatically grow the range to accommodate all lines containing the first separator pattern surrounding the current line. Aug 05, 2011 * g:Align_xstrlen usage extended to permit users to specify a function by name which computes string length. Oct 27, 2011 * (reported by Fco Javier) reported a problem with the default s:Strlen() result; there was a missing "let". Fixed. Nov 10, 2011 * (Lewis Thompson) Align was doing "set noet" when it should've been doing "setlocal noet". Dec 22, 2011 * modifed s:Strlen() to use |strdisplaywidth()| when g:Align_xstrlen is zero. v35 Nov 02, 2008 * g:loaded_AlignPlugin testing to prevent re-loading installed Nov 19, 2008 * new sanity check for an AlignStyle of just ":" Jan 08, 2009 * save&restore of |'mod'| now done with local variant v34 Jul 08, 2008 * using :AlignCtrl before entering any alignment control commands was causing an error. v33 Sep 20, 2007 * s:Strlen() introduced to support various ways used to represent characters and their effects on string lengths. See |align-strlen|. * Align now accepts "..." -- so it can accept whitespace as separators. v32 Aug 18, 2007 * uses || instead of || plus a custom argument splitter to allow patterns with backslashes to slide in unaltered. v31 Aug 06, 2007 * :[range]Align! [AlignCtrl settings] pattern(s) implemented. v30 Feb 12, 2007 * now uses |setline()| v29 Jan 18, 2006 * cecutil updated to use keepjumps Feb 23, 2006 * Align now converted to vim 7.0 style using auto-loading functions. v28 Aug 17, 2005 * report option workaround Oct 24, 2005 * AlignCtrl l: wasn't behaving as expected; fixed v27 Apr 15, 2005 * cpo workaround ignorecase workaround v26 Aug 20, 2004 * loaded_align now also indicates version number GetLatestVimScripts :AutoInstall: now supported v25 Jul 27, 2004 * For debugging, uses Dfunc(), Dret(), and Decho() v24 Mar 03, 2004 * (should've done this earlier!) visualmode(1) not supported until v6.2, now Align will avoid calling it for earlier versions. Visualmode clearing won't take place then, of course. v23 Oct 07, 2003 * Included Leif Wickland's ReplaceQuotedSpaces() function which supports \tsq v22 Jan 29, 2003 * Now requires 6.1.308 or later to clear visualmode() v21 Jan 10, 2003 * BugFix: similar problem to #19; new code bypasses "norm! v\" until initialization is over. v20 Dec 30, 2002 * BugFix: more on "unable to highlight" fixed v19 Nov 21, 2002 * BugFix: some terminals gave an "unable to highlight" message at startup; Hari Krishna Dara tracked it down; a silent! now included to prevent noise. v18 Nov 04, 2002 * BugFix: re-enabled anti-repeated-loading v17 Nov 04, 2002 * BugFix: forgot to have AlignPush() push s:AlignSep AlignCtrl now clears visual-block mode when used so that Align won't try to use old visual-block selection marks '< '> v16 Sep 18, 2002 * AlignCtrl <>| options implemented (separator justification) v15 Aug 22, 2002 * bug fix: AlignCtrl's ":" now acts as a modifier of the preceding alignment operator (lrc) v14 Aug 20, 2002 * bug fix: AlignCtrl default now keeps &ic unchanged bug fix: Align, on end-field, wasn't using correct alignop bug fix: Align, on end-field, was appending padding v13 Aug 19, 2002 * bug fix: zero-length g/v patterns are accepted bug fix: always skip blank lines bug fix: AlignCtrl default now also clears g and v patterns v12 Aug 16, 2002 * moved keep_ic above zero-length pattern checks added "AlignCtrl default" fixed bug with last field getting separator spaces at end line v11 Jul 08, 2002 * prevent separator patterns which match zero length -+: included as additional alignment/justification styles v10 Jun 26, 2002 * =~# used instead of =~ (for matching case) ignorecase option handled v09 Jun 25, 2002 * implemented cyclic padding ALIGNMENT MAP HISTORY *alignmap-history* {{{2 v43 Nov 28, 2012 * changed a lot of maps to use nnoremap (instead of map) Jan 07, 2013 * v42 Jan 06, 2010 * new maps for \anum, \aenum, \aunum Feb 16, 2010 * map for \t=, \T= now handles x++ = something; for c, c++ correctly. Oct 29, 2010 * added a note on having one's own default AlignCtrl (see |alignctrl-init|) Feb 22, 2011 * for menus, &go =~# used to insure correct case Jun 10, 2011 * |:AlignMapsClean| command provided to make it easy for those who would prefer not to have AlignMaps' maps not to have them. v41 Nov 02, 2008 * g:loaded_AlignMapsPlugin testing to prevent re-loading installed * AlignMaps now use 0x0f (ctrl-p) for special character substitutions (instead of 0xff). Seems to avoid some problems with having to use Strlen(). * bug fixed with \ts, * new maps: \ts; \ts, \ts: \ts< \ts= \a( v40 Oct 21, 2008 * Modified AlignMaps so that its maps use s and ".st.et exec "Snippet title ".st.et."" exec "Snippet body ".st.et."".st.et exec "Snippet scriptsrc ".st.et exec "Snippet textarea ".st.et exec "Snippet meta ".st.et exec "Snippet movie classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\"codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\">value=\"".st.et."\" />width=\"".st.et."\" height=\"".st.et."\"controller=\"".st.et."\" autoplay=\"".st.et."\"scale=\"tofit\" cache=\"true\"pluginspage=\"http://www.apple.com/quicktime/download/\"/>".st.et exec "Snippet div
".st.et."
".st.et exec "Snippet mailto ".st.et."".st.et exec "Snippet table
".st.et."
".st.et."
" exec "Snippet link " exec "Snippet form
".st.et."

".st.et exec "Snippet ref ".st.et."".st.et exec "Snippet h1

".st.et."

".st.et exec "Snippet input ".st.et exec "Snippet style ".st.et exec "Snippet base ".st.et work/snippetsEmu/after/ftplugin/java_snippets.vim0000664000000000000000000001026314775444730017601 0ustar if !exists('loaded_snippet') || &cp finish endif function! UpFirst() return substitute(@z,'.','\u&','') endfunction function! JavaTestFileName(type) let filepath = expand('%:p') let filepath = substitute(filepath, '/','.','g') let filepath = substitute(filepath, '^.\(:\\\)\?','','') let filepath = substitute(filepath, '\','.','g') let filepath = substitute(filepath, ' ','','g') let filepath = substitute(filepath, '.*test.','','') if a:type == 1 let filepath = substitute(filepath, '.[A-Za-z]*.java','','g') elseif a:type == 2 let filepath = substitute(filepath, 'Tests.java','','') elseif a:type == 3 let filepath = substitute(filepath, '.*\.\([A-Za-z]*\).java','\1','g') elseif a:type == 4 let filepath = substitute(filepath, 'Tests.java','','') let filepath = substitute(filepath, '.*\.\([A-Za-z]*\).java','\1','g') elseif a:type == 5 let filepath = substitute(filepath, 'Tests.java','','') let filepath = substitute(filepath, '.*\.\([A-Za-z]*\).java','\1','g') let filepath = substitute(filepath, '.','\l&','') endif return filepath endfunction let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet method // {{{ ".st."method".et."/** * ".st.et." */public ".st."return".et." ".st."method".et."() {".st.et."}// }}}".st.et exec "Snippet jps private static final ".st."string".et." ".st.et." = \"".st.et."\";".st.et exec "Snippet jtc try {".st.et."} catch (".st.et." e) {".st.et."} finally {".st.et."}".st.et exec "Snippet jlog /** Logger for this class and subclasses. */protected final Log log = LogFactory.getLog(getClass());".st.et exec "Snippet jpv private ".st."string".et." ".st.et.";".st.et exec "Snippet bean // {{{ set".st."fieldName:UpFirst()".et."/** * Setter for ".st."fieldName".et.". * @param new".st."fieldName:UpFirst()".et." new value for ".st."fieldName".et." */public void set".st."fieldName:UpFirst()".et."(".st."String".et." new".st."fieldName:UpFirst()".et.") {".st."fieldName".et." = new".st."fieldName:UpFirst()".et.";}// }}}// {{{ get".st."fieldName:UpFirst()".et."/** * Getter for ".st."fieldName".et.". * @return ".st."fieldName".et." */public ".st."String".et." get".st."fieldName:UpFirst()".et."() {return ".st."fieldName".et.";}// }}}".st.et exec "Snippet jwh while (".st.et.") { // ".st.et."".st.et."}".st.et exec "Snippet sout System.out.println(\"".st.et."\");".st.et exec "Snippet jtest package ".st."j:JavaTestFileName(1)".et."import junit.framework.TestCase;import ".st."j:JavaTestFileName(2)".et.";/** * ".st."j:JavaTestFileName(3)".et." * * @author ".st.et." * @since ".st.et." */public class ".st."j:JavaTestFileName(3)".et." extends TestCase {private ".st."j:JavaTestFileName(4)".et." ".st."j:JavaTestFileName(5)".et.";public ".st."j:JavaTestFileName(4)".et." get".st."j:JavaTestFileName(4)".et."() { return this.".st."j:JavaTestFileName(5)".et."; }public void set".st."j:JavaTestFileName(4)".et."(".st."j:JavaTestFileName(4)".et." ".st."j:JavaTestFileName(5)".et.") { this.".st."j:JavaTestFileName(5)".et." = ".st."j:JavaTestFileName(5)".et."; }public void test".st.et."() {".st.et."}}".st.et exec "Snippet jif if (".st.et.") { // ".st.et."".st.et."}".st.et exec "Snippet jelse if (".st.et.") { // ".st.et."".st.et."} else { // ".st.et."".st.et."}".st.et exec "Snippet jpm /** * ".st.et." * * @param ".st.et." ".st.et." * ".st.et." ".st.et." */private ".st."void".et." ".st.et."(".st."String".et." ".st.et.") {".st.et."}".st.et exec "Snippet main public main static void main(String[] ars) {".st."\"System.exit(0)\"".et.";}".st.et exec "Snippet jpum /** * ".st.et." * * @param ".st.et." ".st.et." *".st.et." ".st.et." */public ".st."void".et." ".st.et."(".st."String".et." ".st.et.") {".st.et."}".st.et exec "Snippet jcout ".st.et work/snippetsEmu/after/ftplugin/javascript_snippets.vim0000664000000000000000000000056314775444730021030 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet proto ".st."className".et.".prototype.".st."methodName".et." = function(".st.et."){".st.et."};".st.et exec "Snippet fun function ".st."functionName".et." (".st.et."){".st.et."}".st.et work/snippetsEmu/after/ftplugin/latex_snippets.vim0000664000000000000000000000112214775444730017767 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet sub \\subsection{".st."name".et."}\\label{sub:".st."name:substitute(@z,'.','\\l&','g')".et."}".st.et exec "Snippet $$ \\[".st.et."\\]".st.et exec "Snippet ssub \\subsubsection{".st."name".et."}\\label{ssub:".st."name:substitute(@z,'.','\\l&','g')".et."}".st.et exec "Snippet itd \\item[".st."desc".et."] ".st.et exec "Snippet sec \\section{".st."name".et."}\\label{sec:".st."name:substitute(@z,'.','\\l&','g')".et."}".st.et work/snippetsEmu/after/ftplugin/logo_snippets.vim0000664000000000000000000000033514775444730017617 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet to to ".st."name".et." ".st."argument".et."".st.et."end".st.et work/snippetsEmu/after/ftplugin/markdown_snippets.vim0000664000000000000000000000040414775444730020476 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet img ![".st."altText".et."](".st."SRC".et.")".st.et exec "Snippet link [".st."desc".et."](".st."HREF".et.")".st.et work/snippetsEmu/after/ftplugin/movable_type_snippets.vim0000664000000000000000000000076414775444730021353 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet cat <$MTCategoryDescription$>".st.et exec "Snippet blog <$MTBlogName$>".st.et exec "Snippet archive <$MTArchiveFile$>".st.et exec "Snippet cal ".st.et."".st.et exec "Snippet entry <$MTEntryMore$>".st.et exec "Snippet entries ".st.et."".st.et work/snippetsEmu/after/ftplugin/objc_snippets.vim0000664000000000000000000000575014775444730017602 0ustar if !exists('loaded_snippet') || &cp finish endif function! UpFirst() return substitute(@z,'.','\u&','') endfunction function! Count(haystack, needle) let counter = 0 let index = match(a:haystack, a:needle) while index > -1 let counter = counter + 1 let index = match(a:haystack, a:needle, index+1) endwhile return counter endfunction function! ObjCArgList(count) let st = g:snip_start_tag let et = g:snip_end_tag if a:count == 0 return st.et else return st.et.repeat(', '.st.et, a:count) endif endfunction let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet cat @interface ".st."NSObject".et." (".st."Category".et.")@end@implementation ".st."NSObject".et." (".st."Category".et.")".st.et."@end".st.et exec "Snippet delacc - (id)delegate;- (void)setDelegate:(id)delegate;".st.et exec "Snippet ibo IBOutlet ".st."NSSomeClass".et." *".st."someClass".et.";".st.et exec "Snippet dict NSMutableDictionary *".st."dict".et." = [NSMutableDictionary dictionary];".st.et exec "Snippet Imp #import <".st.et.".h>".st.et exec "Snippet objc @interface ".st."class".et." : ".st."NSObject".et."{}@end@implementation ".st."class".et."- (id)init{self = [super init]; if (self != nil){".st.et."}return self;}@end".st.et exec "Snippet imp #import \"".st.et.".h\"".st.et exec "Snippet bez NSBezierPath *".st."path".et." = [NSBezierPath bezierPath];".st.et exec "Snippet acc - (".st."\"unsigned int\"".et.")".st."thing".et."{return ".st."fThing".et.";}- (void)set".st."thing:UpFirst()".et.":(".st."\"unsigned int\"".et.")new".st."thing:UpFirst()".et."{".st."fThing".et." = new".st."thing:UpFirst()".et.";}".st.et exec "Snippet format [NSString stringWithFormat:@\"".st.et."\", ".st.et."]".st.et exec "Snippet focus [self lockFocus];".st.et."[self unlockFocus];".st.et exec "Snippet setprefs [[NSUserDefaults standardUserDefaults] setObject:".st."object".et." forKey:".st."key".et."];".st.et exec "Snippet log NSLog(@\"%s".st."s".et."\", ".st."s:ObjCArgList(Count(@z, '%[^%]'))".et.");".st.et exec "Snippet gsave [NSGraphicsContext saveGraphicsState];".st.et."[NSGraphicsContext restoreGraphicsState];".st.et exec "Snippet forarray for(unsigned int index = 0; index < [".st."array".et." count]; index += 1){".st."id".et."object = [".st."array".et." objectAtIndex:index];".st.et."}".st.et exec "Snippet classi @interface ".st."ClassName".et." : ".st."NSObject".et."{".st.et."}".st.et."@end".st.et exec "Snippet array NSMutableArray *".st."array".et." = [NSMutableArray array];".st.et exec "Snippet getprefs [[NSUserDefaults standardUserDefaults] objectForKey:];".st.et exec "Snippet cati @interface ".st."NSObject".et." (".st."Category".et.")".st.et."@end".st.et work/snippetsEmu/after/ftplugin/ocaml_snippets.vim0000664000000000000000000000252514775444730017755 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet Queue Queue.fold ".st.et." ".st."base".et." ".st."q".et."".st.et exec "Snippet Nativeint Nativeint.abs ".st."ni".et.st.et exec "Snippet Printexc Printexc.print ".st."fn".et." ".st."x".et.st.et exec "Snippet Sys Sys.Signal_ignore".st.et exec "Snippet Hashtbl Hashtbl.iter ".st.et." ".st."h".et.st.et exec "Snippet Array Array.map ".st.et." ".st."arr".et.st.et exec "Snippet Printf Printf.fprintf ".st."buf".et." \"".st."format".et."\" ".st."args".et.st.et exec "Snippet Stream Stream.iter ".st.et." ".st."stream".et.st.et exec "Snippet Buffer Buffer.add_channel ".st."buf".et." ".st."ic".et." ".st."len".et.st.et exec "Snippet Int32 Int32.abs ".st."i32".et.st.et exec "Snippet List List.rev_map ".st.et." ".st."lst".et.st.et exec "Snippet Scanf Scanf.bscaf ".st."sbuf".et." \"".st."format".et."\" ".st."f".et.st.et exec "Snippet Int64 Int64.abs ".st."i64".et.st.et exec "Snippet Map Map.Make ".st.et exec "Snippet String String.iter ".st.et." ".st."str".et.st.et exec "Snippet Genlex Genlex.make_lexer ".st."\"tok_lst\"".et." ".st."\"char_stream\"".et.st.et exec "Snippet for for ".st."i}".et." = ".st.et." to ".st.et." do".st.et."done".st.et exec "Snippet Stack Stack.iter ".st.et." ".st."stk".et.st.et work/snippetsEmu/after/ftplugin/perl_snippets.vim0000664000000000000000000000324114775444730017620 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet sub sub ".st."FunctionName".et." {".st.et."}".st.et exec "Snippet class package ".st."ClassName".et.";".st.et.st."ParentClass".et.st.et.";sub new {my \$class = shift;\$class = ref \$class if ref \$class;my $self = bless {}, \$class;\$self;}1;".st.et exec "Snippet xfore ".st."expression".et." foreach @".st."array".et.";".st.et exec "Snippet xwhile ".st."expression".et." while ".st."condition".et.";".st.et exec "Snippet xunless ".st."expression".et." unless ".st."condition".et.";".st.et exec "Snippet slurp my $".st."var".et.";{ local $/ = undef; local *FILE; open FILE, \"<".st."file".et.">\"; $".st."var".et." = ; close FILE }".st.et exec "Snippet if if (".st.et.") {".st.et."}".st.et exec "Snippet unless unless (".st.et.") {".st.et."}".st.et exec "Snippet ifee if (".st.et.") {".st.et."} elsif (".st.et.") {".st.et."} else {".st.et."}".st.et exec "Snippet ife if (".st.et.") {".st.et."} else {".st.et."}".st.et exec "Snippet for for (my \$".st."var".et." = 0; \$".st."var".et." < ".st."expression".et."; \$".st."var".et."++) {".st.et."}".st.et exec "Snippet fore foreach my \$".st."var".et." (@".st."array".et.") {".st.et."}".st.et exec "Snippet eval eval {".st.et."};if ($@) {".st.et."}".st.et exec "Snippet while while (".st.et.") {".st.et."}".st.et exec "Snippet xif ".st."expression".et." if ".st."condition".et.";".st.et work/snippetsEmu/after/ftplugin/php_snippets.vim0000664000000000000000000000443714775444730017455 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet elseif elseif ( ".st."condition".et." ){".st.et."}".st.et exec "Snippet do do{".st.et."} while ( ".st.et." );".st.et exec "Snippet reql require_once( '".st."file".et."' );".st.et exec "Snippet if? $".st."retVal".et." = ( ".st."condition".et." ) ? ".st."a".et." : ".st."b".et." ;".st.et exec "Snippet phpp ".st.et."?>" exec "Snippet switch switch ( ".st."variable".et." ){case '".st."value".et."':".st.et."break;".st.et."default:".st.et."break;}".st.et exec "Snippet class #doc#classname:".st."ClassName".et."#scope:".st."PUBLIC".et."##/docclass ".st."ClassName".et." ".st."extendsAnotherClass".et."{#internal variables#Constructorfunction __construct ( ".st."argument".et."){".st.et."}###}###".st.et exec "Snippet incll include_once( '".st."file".et."' );".st.et exec "Snippet incl include( '".st."file".et."' );".st.et exec "Snippet foreach foreach( $".st."variable".et." as $".st."key".et." => $".st."value".et." ){".st.et."}".st.et exec "Snippet ifelse if ( ".st."condition".et." ){".st.et."}else{".st.et."}".st.et exec "Snippet $_ $_REQUEST['".st."variable".et."']".st.et exec "Snippet case case '".st."variable".et."':".st.et."break;".st.et exec "Snippet print print \"".st."string".et."\"".st.et.";".st.et."".st.et exec "Snippet function ".st."public".et."function ".st."FunctionName".et." (".st.et."){".st.et."}".st.et exec "Snippet if if ( ".st."condition".et." ){".st.et."}".st.et exec "Snippet else else{".st.et."}".st.et exec "Snippet array $".st."arrayName".et." = array( '".st.et."',".st.et." );".st.et exec "Snippet -globals $GLOBALS['".st."variable".et."']".st.et.st."something".et.st.et.";".st.et exec "Snippet req require( '".st."file".et."' );".st.et exec "Snippet for for ( $".st."i".et."=".st.et."; $".st."i".et." < ".st.et."; $".st."i".et."++ ){ ".st.et."}".st.et exec "Snippet while while ( ".st.et." ){".st.et."}".st.et work/snippetsEmu/after/ftplugin/phpdoc_snippets.vim0000664000000000000000000000364214775444730020140 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet doc_d /*** ".st."undocumentedConstant".et."**/define(".st.et.", ".st.et.");".st.et."".st.et exec "Snippet doc_vp /*** ".st."undocumentedClassVariable".et."** @var ".st."string".et.st.et."**/".st.et."" exec "Snippet doc_f /*** ".st."undocumentedFunction".et."** @return ".st."void".et."* @author ".st.et."**/".st.et."function ".st.et."(".st.et."){".st.et."}".st.et exec "Snippet doc_s /*** ".st."undocumentedFunction".et."** @return ".st."void".et."* @author ".st.et."**/".st.et."function ".st.et."(".st.et.");".st.et exec "Snippet doc_h /*** ".st.et."** @author ".st.et."* @version $Id$* @copyright ".st.et.", ".st.et."* @package ".st."default".et."**//*** Define DocBlock**/".st.et exec "Snippet doc_fp /*** ".st."undocumentedFunction".et."** @return ".st."void".et."* @author ".st.et."**/".st.et."" exec "Snippet doc_i /*** ".st."undocumentedClass".et."** @package ".st."default".et."* @author ".st.et."**/interface ".st.et."{".st.et."} // END interface ".st.et."".st.et exec "Snippet doc_fp /*** ".st."undocumentedConstant".et.st.et."**/".st.et."".st.et exec "Snippet doc_v /*** ".st."undocumentedClassVariable".et."** @var ".st."string".et."**/ $".st.et.";".st.et."".st.et exec "Snippet doc_cp /*** ".st."undocumentedClass".et."** @package ".st."default".et."* @author ".st.et."**/".st.et exec "Snippet doc_c /*** ".st."undocumentedClass".et."** @package ".st."default".et."* @author ".st.et."**/".st."class".et."class ".st."a".et."{".st.et."} // END ".st."class".et."class ".st."a".et."".st.et work/snippetsEmu/after/ftplugin/propel_snippets.vim0000664000000000000000000000157614775444730020170 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet ".st.et exec "Snippet ".st.et."".st.et exec "Snippet
".st.et exec "Snippet ".st.et exec "Snippet

".st.et exec "Snippet \"/>".st.et work/snippetsEmu/after/ftplugin/python_snippets.vim0000664000000000000000000001523714775444730020207 0ustar if !exists('loaded_snippet') || &cp finish endif " Given a string containing a list of arguments (e.g. "one, two = 'test'"), " this function cleans it up by removing useless whitespace and commas. function! PyCleanupArgs(text) if a:text == 'args' return '' endif let text = substitute(a:text, '\(\w\)\s\(\w\)', '\1,\2', 'g') return join(split(text, '\s*,\s*'), ', ') endfunction " Given a string containing a list of arguments (e.g. "one = 'test', *args, " **kwargs"), this function returns a string containing only the variable " names, separated by spaces, e.g. "one two". function! PyGetVarnamesFromArgs(text) let text = substitute(a:text, 'self,*\s*', '', '') let text = substitute(text, '\*\*\?\k\+', '', 'g') let text = substitute(text, '=.\{-},', '', 'g') let text = substitute(text, '=.\{-}$', '', 'g') let text = substitute(text, '\s*,\s*', ' ', 'g') if text == ' ' return '' endif return text endfunction " Returns the current indent as a string. function! PyGetIndentString() if &expandtab let tabs = indent('.') / &shiftwidth let tabstr = repeat(' ', &shiftwidth) else let tabs = indent('.') / &tabstop let tabstr = '\t' endif return repeat(tabstr, tabs) endfunction " Given a string containing a list of arguments (e.g. "one = 'test', *args, " **kwargs"), this function returns them formatted correctly for the " docstring. function! PyGetDocstringFromArgs(text) let text = PyGetVarnamesFromArgs(a:text) if a:text == 'args' || text == '' return '' endif let indent = PyGetIndentString() let st = g:snip_start_tag let et = g:snip_end_tag let docvars = map(split(text), 'v:val." -- ".st.et') return '\n'.indent.join(docvars, '\n'.indent).'\n'.indent endfunction " Given a string containing a list of arguments (e.g. "one = 'test', *args, " **kwargs"), this function returns them formatted as a variable assignment in " the form "self._ONE = ONE", as used in class constructors. function! PyGetVariableInitializationFromVars(text) let text = PyGetVarnamesFromArgs(a:text) if a:text == 'args' || text == '' return '' endif let indent = PyGetIndentString() let st = g:snip_start_tag let et = g:snip_end_tag let assert_vars = map(split(text), '"assert ".v:val." ".st.et') let assign_vars = map(split(text), '"self._".v:val." = ".v:val') let assertions = join(assert_vars, '\n'.indent) let assignments = join(assign_vars, '\n'.indent) return assertions.'\n'.indent.assignments.'\n'.indent endfunction " Given a string containing a list of arguments (e.g. "one = 'test', *args, " **kwargs"), this function returns them with the default arguments removed. function! PyStripDefaultValue(text) return substitute(a:text, '=.*', '', 'g') endfunction " Returns the number of occurences of needle in haystack. function! Count(haystack, needle) let counter = 0 let index = match(a:haystack, a:needle) while index > -1 let counter = counter + 1 let index = match(a:haystack, a:needle, index+1) endwhile return counter endfunction " Returns replacement if the given subject matches the given match. " Returns the subject otherwise. function! PyReplace(subject, match, replacement) if a:subject == a:match return a:replacement endif return a:subject endfunction " Returns the % operator with a tuple containing n elements appended, where n " is the given number. function! PyHashArgList(count) if a:count == 0 return '' endif let st = g:snip_start_tag let et = g:snip_end_tag return ' % ('.st.et.repeat(', '.st.et, a:count - 1).')' endfunction let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim " Note to users: The following method of defininf snippets is to allow for " changes to the default tags. " Feel free to define your own as so: " Snippet mysnip This is the expansion text.<{}> " There is no need to use exec if you are happy to hardcode your own start and " end tags " Properties, setters and getters. exec "Snippet prop ".st."attribute".et." = property(get_".st."attribute".et.", set_".st."attribute".et.st.et.")".st.et exec "Snippet get def get_".st."name".et."(self):return self._".st."name".et."".st.et exec "Snippet set def set_".st."name".et."(self, ".st."value".et."): \self._".st."name".et." = ".st."value:PyStripDefaultValue(@z)".et." \".st.et " Functions and methods. exec "Snippet def def ".st."fname".et."(".st."args:PyCleanupArgs(@z)".et."): \\"\"\" \".st.et." \".st."args:PyGetDocstringFromArgs(@z)".et."\"\"\" \".st."pass".et." \".st.et exec "Snippet cm ".st."class".et." = classmethod(".st."class".et.")".st.et " Class definition. exec "Snippet cl class ".st."ClassName".et."(".st."object".et."): \\"\"\" \This class represents ".st.et." \\"\"\" \ \def __init__(self, ".st."args:PyCleanupArgs(@z)".et."): \\"\"\" \Constructor. \".st."args:PyGetDocstringFromArgs(@z)".et."\"\"\" \".st."args:PyGetVariableInitializationFromVars(@z)".et.st.et " Keywords exec "Snippet for for ".st."variable".et." in ".st."ensemble".et.":".st."pass".et."".st.et exec "Snippet pf print '".st."s".et."'".st."s:PyHashArgList(Count(@z, '%[^%]'))".et."".st.et exec "Snippet im import ".st."module".et."".st.et exec "Snippet from from ".st."module".et." import ".st.'name:PyReplace(@z, "name", "*")'.et."".st.et exec "Snippet % '".st."s".et."'".st."s:PyHashArgList(Count(@z, '%[^%]'))".et.st.et exec "Snippet ass assert ".st."expression".et.st.et " From Kib2 exec "Snippet bc \"\"\"".st.et."\"\"\"".st.et " Try, except, finally. exec "Snippet trye try: \".st.et." \except Exception, e: \".st.et." \".st.et exec "Snippet tryf try: \".st.et." \finally: \".st.et." \".st.et exec "Snippet tryef try: \".st.et." \except Exception, e: \".st.et." \finally: \".st.et." \".st.et " Other multi statement templates " From Panos exec "Snippet ifn if __name__ == '".st."main".et."':".st.et exec "Snippet ifmain if __name__ == '__main__':".st.et " Shebang exec "Snippet sb #!/usr/bin/env python# -*- coding: ".st."encoding".et." -*-".st.et exec "Snippet sbu #!/usr/bin/env python# -*- coding: UTF-8 -*-".st.et " From Kib2 exec "Snippet sbl1 #!/usr/bin/env python# -*- coding: Latin-1 -*-".st.et " Unit tests. exec "Snippet unittest if __name__ == '__main__': \import unittest \ \class ".st."ClassName".et."Test(unittest.TestCase): \def setUp(self): \".st."pass".et." \ \def runTest(self): \".st.et work/snippetsEmu/after/ftplugin/rails_snippets.vim0000664000000000000000000001023714775444730017773 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet mrnt rename_table \"".st."oldTableName".et."\", \"".st."newTableName".et."\"".st.et exec "Snippet rfu render :file => \"".st."filepath".et."\", :use_full_path => ".st."false".et.st.et exec "Snippet rns render :nothing => ".st."true".et.", :status => ".st.et.st.et exec "Snippet ri render :inline => \"".st.et."\")>\"".st.et exec "Snippet rt render :text => \"".st.et."\"".st.et exec "Snippet mcc t.column \"".st."title".et."\", :".st."string".et.st.et exec "Snippet rpl render :partial => \"".st."item".et."\", :locals => { :".st."name".et." => \"".st."value".et."\"".st.et." }".st.et exec "Snippet rea redirect_to :action => \"".st."index".et."\"".st.et exec "Snippet rtlt render :text => \"".st.et."\", :layout => ".st."true".et.st.et exec "Snippet ft <%= form_tag :action => \"".st."update".et."\" %>".st.et exec "Snippet forin <% for ".st."item".et." in ".st.et." %><%= ".st."item".et.".".st."name".et." %><% end %>".st.et exec "Snippet lia <%= link_to \"".st.et."\", :action => \"".st."index".et."\" %>".st.et exec "Snippet rl render :layout => \"".st."layoutname".et."\"".st.et exec "Snippet ra render :action => \"".st."action".et."\"".st.et exec "Snippet mrnc rename_column \"".st."table".et."\", \"".st."oldColumnName".et."\", \"".st."newColumnName".et."\"".st.et exec "Snippet mac add_column \"".st."table".et."\", \"".st."column".et."\", :".st."string".et.st.et exec "Snippet rpc render :partial => \"".st."item".et."\", :collection => ".st."items".et.st.et exec "Snippet rec redirect_to :controller => \"".st."items".et."\"".st.et exec "Snippet rn render :nothing => ".st."true".et.st.et exec "Snippet lic <%= link_to \"".st.et."\", :controller => \"".st.et."\" %>".st.et exec "Snippet rpo render :partial => \"".st."item".et."\", :object => ".st."object".et.st.et exec "Snippet rts render :text => \"".st.et."\", :status => ".st.et exec "Snippet rcea render_component :action => \"".st."index".et."\"".st.et exec "Snippet recai redirect_to :controller => \"".st."items".et."\", :action => \"".st."show".et."\", :id => ".st.et exec "Snippet mcdt create_table \"".st."table".et."\" do |t|".st.et."end".st.et exec "Snippet ral render :action => \"".st."action".et."\", :layout => \"".st."layoutname".et."\"".st.et exec "Snippet rit render :inline => \"".st.et."\", :type => ".st.et exec "Snippet rceca render_component :controller => \"".st."items".et."\", :action => \"".st."index".et."\"".st.et exec "Snippet licai <%= link_to \"".st.et."\", :controller => \"".st."items".et."\", :action => \"".st."edit".et."\", :id => ".st.et." %>".st.et exec "Snippet verify verify :only => [:".st.et."], :method => :post, :render => {:status => 500, :text => \"use HTTP-POST\"}".st.et exec "Snippet mdt drop_table \"".st."table".et."\"".st.et exec "Snippet rp render :partial => \"".st."item".et."\"".st.et exec "Snippet rcec render_component :controller => \"".st."items".et."\"".st.et exec "Snippet mrc remove_column \"".st."table".et."\", \"".st."column".et."\"".st.et exec "Snippet mct create_table \"".st."table".et."\" do |t|".st.et."end".st.et exec "Snippet flash flash[:".st."notice".et."] = \"".st.et."\"".st.et exec "Snippet rf render :file => \"".st."filepath".et."\"".st.et exec "Snippet lica <%= link_to \"".st.et."\", :controller => \"".st."items".et."\", :action => \"".st."index".et."\" %>".st.et exec "Snippet liai <%= link_to \"".st.et."\", :action => \"".st."edit".et."\", :id => ".st.et." %>".st.et exec "Snippet reai redirect_to :action => \"".st."show".et."\", :id => ".st.et exec "Snippet logi logger.info \"".st.et."\"".st.et exec "Snippet marc add_column \"".st."table".et."\", \"".st."column".et."\", :".st."string".et."".st.et."".st.et exec "Snippet rps render :partial => \"".st."item".et."\", :status => ".st.et exec "Snippet ril render :inline => \"".st.et."\", :locals => { ".st.et." => \"".st."value".et."\"".st.et." }".st.et exec "Snippet rtl render :text => \"".st.et."\", :layout => \"".st.et."\"".st.et exec "Snippet reca redirect_to :controller => \"".st."items".et."\", :action => \"".st."list".et."\"".st.et work/snippetsEmu/after/ftplugin/ruby_snippets.vim0000664000000000000000000000462014775444730017641 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet do do".st.et."end".st.et exec "Snippet class class ".st."className".et."".st.et."end".st.et exec "Snippet begin begin".st.et."rescue ".st."Exception".et." => ".st."e".et."".st.et."end".st.et exec "Snippet each_with_index0 each_with_index do |".st."element".et.", ".st."index".et."|".st."element".et.".".st.et."end".st.et exec "Snippet collect collect { |".st."element".et."| ".st."element".et.".".st.et." }".st.et exec "Snippet forin for ".st."element".et." in ".st."collection".et."".st."element".et.".".st.et."end".st.et exec "Snippet doo do |".st."object".et."|".st.et."end".st.et exec "Snippet : :".st."key".et." => \"".st."value".et."\"".st.et."".st.et exec "Snippet def def ".st."methodName".et."".st.et."end".st.et exec "Snippet case case ".st."object".et."when ".st."condition".et."".st.et."end".st.et exec "Snippet collecto collect do |".st."element".et."|".st."element".et.".".st.et."end".st.et exec "Snippet each each { |".st."element".et."| ".st."element".et.".".st.et." }".st.et exec "Snippet each_with_index each_with_index { |".st."element".et.", ".st."idx".et."| ".st."element".et.".".st.et." }".st.et exec "Snippet if if ".st."condition".et."".st.et."end".st.et exec "Snippet eacho each do |".st."element".et."|".st."element".et.".".st.et."end".st.et exec "Snippet unless unless ".st."condition".et."".st.et."end".st.et exec "Snippet ife if ".st."condition".et."".st.et."else".st.et."end".st.et exec "Snippet when when ".st."condition".et."".st.et exec "Snippet selecto select do |".st."element".et."|".st."element".et.".".st.et."end".st.et exec "Snippet injecto inject(".st."object".et.") do |".st."injection".et.", ".st."element".et."| ".st.et."end".st.et exec "Snippet reject { |".st."element".et."| ".st."element".et.".".st.et." }".st.et exec "Snippet rejecto reject do |".st."element".et."| ".st."element".et.".".st.et."end".st.et exec "Snippet inject inject(".st."object".et.") { |".st."injection".et.", ".st."element".et."| ".st.et." }".st.et exec "Snippet select select { |".st."element".et."| ".st."element".et.".".st.et." }".st.et work/snippetsEmu/after/ftplugin/sh_snippets.vim0000664000000000000000000000075014775444730017272 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim "Snippet !env #!/usr/bin/env ${1:${TM_SCOPE/(?:source|.*)\\.(\\w+).*/$1/}} exec "Snippet if if [[ ".st."condition".et." ]]; then".st.et."fi".st.et exec "Snippet elif elif [[ ".st."condition".et." ]]; then".st.et exec "Snippet for for (( ".st."i".et." = ".st.et."; ".st."i".et." ".st.et."; ".st."i".et.st.et." )); do".st.et."done".st.et work/snippetsEmu/after/ftplugin/slate_snippets.vim0000664000000000000000000000207214775444730017767 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet do do: [| :".st."each".et."| ".st.et."]".st.et exec "Snippet proto define: #".st."NewName".et." &parents: {".st."parents".et."} &slots: {".st."slotSpecs".et."}.".st.et exec "Snippet ifte ".st."condition".et." ifTrue: [".st.et.":then] ifFalse: [".st.et.":else]".st.et exec "Snippet collect collect: [| :".st."each".et."| ".st.et."]".st.et exec "Snippet if ".st."condition".et." ifTrue: [".st.et.":then]".st.et exec "Snippet until [".st."condition".et."] whileFalse: [".st.et.":body]".st.et exec "Snippet reject reject: [| :".st."each".et."| ".st.et."]".st.et exec "Snippet dowith doWithIndex: [| :".st."each".et." :".st."index".et." | ".st.et."]".st.et exec "Snippet select select: [| :".st."each".et."| ".st.et."]".st.et exec "Snippet while [".st."condition".et."] whileTrue: [".st.et.":body]".st.et exec "Snippet inject inject: ".st."object".et." [| :".st."injection".et.", :".st."each".et."| ".st.et."]".st.et work/snippetsEmu/after/ftplugin/smarty_snippets.vim0000664000000000000000000000470414775444730020202 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet {cycle {cycle values=\"#SELSTART#".st."foo".et.",".st."bar".et."#SELEND#\" name=\"default\" print=true advance=true delimiter=\",\" assign=varname }".st.et exec "Snippet |regex_replace |regex_replace:\"".st."regex".et."\":\"".st.et."\"".st.et exec "Snippet {counter {counter name=\"#INSERTION#\" start=1 skip=1 direction=\"up\" print=trueassign=\"foo\" }{counter}".st.et exec "Snippet {eval {eval var=\"#SELSTART#{template_format}#SELEND#\" assign=varname} ".st.et "Snippet |date_format |date_format:"${1:strftime() formatting}" <{}> exec "Snippet |truncate |truncate:".st.et.":".st.et.":".st."false".et."" exec "Snippet {if {if ".st."varname".et.st.et."\"".st."foo".et."\"}{* $varname can also be a php call *}".st.et."{/if}".st.et "Snippet |string_format |string_format:"${1:sprintf formatting}" <{}> exec "Snippet {assign {assign var=".st.et." value=\"".st.et."\"}".st.et exec "Snippet {foreach {foreach from=".st."varname".et." item=i [key=k name=\"\"] }".st.et."{/foreach}".st.et exec "Snippet {capture {capture name=#INSERTION#}#SELECT#{/capture}".st.et exec "Snippet |wordwrap |wordwrap:".st.et.":\"".st.et."\":".st.et exec "Snippet |spacify |spacify:\"".st.et."\"".st.et." " exec "Snippet |default |default:\"".st.et."\"".st.et exec "Snippet {debug {debug output=\"#SELSTART#".st.et."#SELEND#\" }".st.et exec "Snippet |replace |replace:\"".st."needle".et."\":\"".st.et."\"".st.et exec "Snippet {include {include file=\"".st.et."\" [assign=varname foo=\"bar\"] }".st.et exec "Snippet |escape |escape:\"".st.et."\"".st.et exec "Snippet {strip {strip}".st.et."{/strip}".st.et exec "Snippet {math {math equation=\"".st.et."\" assign=".st.et." ".st.et."}".st.et exec "Snippet {config_load {config_load file=\"#INSERTION#\" [section=\"\" scope=\"local|parent|global\"] }".st.et exec "Snippet |cat |cat:\"".st.et."\"".st.et exec "Snippet {insert {insert name=\"insert_".st.et."\" [assign=varname script=\"foo.php\" foo=\"bar\"] }".st.et exec "Snippet {fetch {fetch file=\"#SELSTART#http:// or file#SELEND#\" assign=varname}".st.et exec "Snippet {literal {literal}".st.et."{/literal}".st.et exec "Snippet {include_php {include_php file=\"".st.et."\" [once=true]}".st.et exec "Snippet |strip |strip:[\"".st.et."\"]".st.et work/snippetsEmu/after/ftplugin/symfony_snippets.vim0000664000000000000000000000305114775444730020361 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet image_tag image_tag('".st."imageName".et."'".st.et.")".st.et exec "Snippet get public function get".st.et." (){return $this->".st.et.";}".st.et exec "Snippet link_to link_to('".st."linkName".et."', '".st."moduleName".et."/".st."actionName".et.st.et."')".st.et exec "Snippet sexecute public function execute(){".st.et."}".st.et exec "Snippet set public function set".st.et." ($".st.et."){$this->".st.et." = ".st.et.";}".st.et exec "Snippet execute /*** ".st."className".et."**/public function execute(){".st.et."}".st.et exec "Snippet tforeach ".st.et."".st.et exec "Snippet getparam $this->getRequestParameter('".st."id".et."')".st.et exec "Snippet div ".st.et."".st.et exec "Snippet tif ".st.et."".st.et exec "Snippet setget public function set".st."var".et." (".st."arg".et."){$this->".st."arg".et." = ".st."arg".et.";}public function get".st."var".et." (){return $this->".st."var".et.";}".st.et exec "Snippet echo ".st.et exec "Snippet tfor ".st.et."".st.et work/snippetsEmu/after/ftplugin/tcl_snippets.vim0000664000000000000000000000131114775444730017434 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet switch switch ".st.et." -- $".st."var".et." {".st."match".et." {".st.et."}default{".st.et."}}".st.et exec "Snippet foreach foreach ".st."var".et." $".st."list".et." {".st.et."}".st.et exec "Snippet proc proc ".st."name".et." {".st."args".et."} {".st.et."}".st.et exec "Snippet if if {".st."condition".et."} {".st.et."}".st.et exec "Snippet for for {".st."i".et." {".st.et."} {".st.et."} {".st.et."}".st.et exec "Snippet while while {".st."condition".et."} {".st.et."}".st.et work/snippetsEmu/after/ftplugin/template_toolkit_snippets.vim0000664000000000000000000000111214775444730022231 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet wrap [% WRAPPER ".st."template".et." %]".st.et."[% END %]".st.et exec "Snippet if [% IF ".st."condition".et." %]".st.et."[% ELSE %]".st.et."[% END %]".st.et exec "Snippet unl [% UNLESS ".st."condition".et." %]".st.et."[% END %]".st.et exec "Snippet inc [% INCLUDE ".st."template".et." %]".st.et exec "Snippet for [% FOR ".st."var".et." IN ".st."set".et." %]".st.et."[% END %]".st.et work/snippetsEmu/after/ftplugin/tex_snippets.vim0000664000000000000000000000112114775444730017451 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet sub \\subsection{".st."name".et."}\\label{sub:".st."name:substitute(@z,'.','\\l&','g')".et."}".st.et exec "Snippet $$ \\[".st.et."\\]".st.et exec "Snippet ssub \\subsubsection{".st."name".et."}\\label{ssub:".st."name:substitute(@z,'.','\\l&','g')".et."}".st.et exec "Snippet itd \\item[".st."desc".et."] ".st.et exec "Snippet sec \\section{".st."name".et."}\\label{sec:".st."name:substitute(@z,'.','\\l&','g')".et."".st.et work/snippetsEmu/after/ftplugin/xhtml_snippets.vim0000664000000000000000000001024514775444730020014 0ustar if !exists('loaded_snippet') || &cp finish endif let st = g:snip_start_tag let et = g:snip_end_tag let cd = g:snip_elem_delim exec "Snippet doctype \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">".st.et exec "Snippet aref ".st.et."".st.et exec "Snippet head ".st.et."".st.et exec "Snippet script ".st.et exec "Snippet html lang=\"".st."en".et."\">".st.et."" exec "Snippet h3

".st.et."

".st.et exec "Snippet h4

".st.et."

".st.et exec "Snippet h5
".st.et."
".st.et exec "Snippet h6
".st.et."
".st.et exec "Snippet fieldset
".st.et."
".st.et exec "Snippet noscript ".st.et exec "Snippet ul
    ".st.et."
".st.et exec "Snippet xml ".st.et exec "Snippet body ".st.et."".st.et exec "Snippet legend ".st.et."".st.et exec "Snippet title ".st."PageTitle".et."".st.et exec "Snippet scriptsrc ".st.et exec "Snippet img \"".st.et."\"".st.et exec "Snippet option ".st.et exec "Snippet optgroup ".st.et."".st.et exec "Snippet meta ".st.et exec "Snippet td ".st.et."".st.et exec "Snippet dt
".st.et."
".st.et."
".st.et exec "Snippet tfoot ".st.et."".st.et exec "Snippet div
".st.et."
".st.et exec "Snippet ol
    ".st.et."
".st.et exec "Snippet txtarea ".st.et exec "Snippet mailto ".st.et."".st.et exec "Snippet table ".st.et."
".st.et exec "Snippet hint ".st.et."".st.et exec "Snippet link ".st.et exec "Snippet form
".st.et."".st.et exec "Snippet tr ".st.et."".st.et exec "Snippet label ".st.et exec "Snippet image \"".st.et."\"".st.et exec "Snippet input ".st.et exec "Snippet select ".st.et exec "Snippet style ".st.et exec "Snippet divheader

".st."CompanyName".et."

".st.et exec "Snippet base ".st.et work/snippetsEmu/doc/0000775000000000000000000000000014775444730012030 5ustar work/snippetsEmu/doc/snippets_emu.txt0000664000000000000000000003360014775444730015306 0ustar *snippets_emu.txt* For Vim version 7.0. Last change: 2006 Dec 26 VIM REFERENCE MANUAL by Panos Laganakos and Felix Ingram 1. SnippetsEmu Features |snippets_emu-features| Basic Snippets |basic-snippet| Named Tags |named-tags| Tag Commands |snippet-commands| Buffer Specific Snippets |snip-buffer-specific| Filetype Specific Snippets |snip-ftplugin| Snippets menu |snip-menu| 2. SnippetsEmu Options |snippets_emu-options| Start and End Tags |snip-start-end-tags| Element Delimiter |snip-start-end-tags| Remapping the default jump key |snip-remap-key| 3. Detailed Explanations |snip-detailed-explanations| Valid Tag Names |snip-tag-name-syntax| Advanced Tag Command Examples |snip-advanced-tag-commands| 4. SnippetsEmu Contact Details |snip-contact-details| 5. Contributors |snip-contributors| 6. SnippetsEmu Known Bugs |snippets_emu-bugs| 7. Troubleshooting |snippets_emu-troubleshooting| {Vi does not have any of these features} ============================================================================== SNIPPETSEMU FEATURES *snippets_emu-features* SnippetsEmu attempts to emulate several of the snippets features of the OS X editor TextMate, in particular the variable bouncing and replacement behaviour. Simple usage is built up around the following functionality: Basic Snippet |basic-snippet| Named Tags |named-tags| Executable Snippet |snippet-commands| Buffer Specific Snippets |snip-buffer-specific| *basic-snippet* *:Snippet* Basic Snippet ~ A basic snippet can save you a lot of typing. Define a word trigger and on insertion it will be expanded to the full snippet. SnippetsEmu allows the user to define markers within the larger piece of text which will be used to place the cursor upon expansion. The command used to define a snippet is 'Snippet'. Basic Syntax: > :Snippet trigger_name The cursor will be placed here: <{}> Trailing text In insert mode typing 'trigger_name' will remove 'trigger_name' and replace it with the text: 'The cursor will be placed here: Trailing text'. The cursor will be placed between the two spaces before the word 'Trailing' NOTE: All text should be entered on the same command line. The formatting of this document may mean that examples are wrapped but they should all be entered on a single line. *named-tags* Named tags ~ Instead of the simple '<{}>' tags used for cursor placement a user can define named tags. When the value of a named tag is changed then all other tags with that name will be changed to the same value. E.g. > :Snippet trigger My name is <{forename}> <{surname}>. Call me <{forename}>. In insert mode typing 'trigger' will place the cursor inside the '<{forename}>' tag. Whatever is entered inside the tag will replace the other similarly named tag at the end of the line after the user presses 'Tab'. If no value is entered for a named tag then the tag's name will be used instead. This is one way of defining default values. Using the above example, entering 'trigger' and pressing 'Tab' twice will result in the following text: > My name is forename surname. Please call me forename. The rules for what constitutes a valid tag name are explained below. See |snip-tag-name-syntax|. *snippet-commands* Tag commands ~ Tags can contain commands. Commands can be any Vim function, including user defined functions. A common example is performing substitutions. E.g. > :Snippet trigger My name is <{name}>. I SAID: MY NAME IS <{name:substitute(@z,'.','\u&','g')}>! The value entered in the <{name}> tag will be passed to the command in the second <{name}> tag in the @z register (any value already in @z will be preserved and restored). The substitute command will change the entered value to be in upper case. I.e. Entering 'trigger' and typing 'Tycho' will result in the following text: > My name is Tycho. I SAID: MY NAME IS TYCHO! ~ *snip-special-vars* There is a set of special variables which can be included in snippets. These will be replaced before the snippet's text is inserted into the buffer. The list of available variables is detailed below: * SNIP_FILE_NAME - The current file name (from 'expand("%")') * SNIP_ISO_DATE - The current date in YYYY-MM-DD format. *snip-snippet-commands* In addition to tag commands it is also possible to define commands which will be executed before the snippet is inserted into the buffer. These are defined within double backticks. E.g. > :Snippet date The current date is ``strftime("%c")`` Commands are standard Vim commands and will be 'exec'uted and the command output substituted into the text. *snip-buffer-specific* Buffer Specific Snippets ~ The Snippet command defines buffer specific snippets. This is the recommended option when using filetype specific snippets. It is possible to define 'global' snippets which will act across all buffers. These can be defined using the legacy 'Iabbr' command (note the capital 'I'). E.g. > Iabbr for for <{var}> in <{list}>:<{}> ~ *snip-ftplugin* The preferred practice for defining filetype specific snippets is to include them in files named _snippets.vim and for these files to be placed in the ~/.vim/after/ftplugin directory (or vimfiles\after\ftplugin under Windows). When a file of a specific type is loaded so will all of the defined snippets. The 'after' directory is used to ensure that the plugin has been loaded. It is also recommended that the following is included at the top of the file: > if !exists('loaded_snippet') || &cp finish endif This will stop errors being generated if the plugin has not loaded for any reason. Users wishing to add their own filetype snippets should add them to a separate file to ensure they are not lost when upgrading the plugin. Naming the files _mysnippets.vim or similar is the preferred practice. *snip-menu* When loading the plugin will search for all files named '*_snippets.vim'. These will be added to the 'Snippets' menu which is available in Normal mode. Selecting options from the menu will source the file and hence load any snippets defined within it. *creating-snippets* *CreateSnippet* [range]CreateSnippet The CreateSnippet command allows the simple creation of snippets for use within your own file. Without a range the current line will be used. When passed a range then all the lines in the range will be converted for use in a command. Snippets created by the command will be added to a scratch buffer called 'Snippets'. The current value of an empty tag (snip_start_tag.snip_end_tag, '<{}>' by default) will be added to the unnamed register and so can be inserted with appropriate paste commands. *CreateBundleSnippet* [range]CreateBundleSnippet CreateBundleSnippet works exactly like CreateSnippet but the resulting text will be suitable for including in one of the included bundles. The unnamed register will include the text '"st.et."' so start and end tag agnostic empty tags can be included. =============================================================================== SNIPPETSEMU OPTIONS *snippets_emu-options* *snip-start-end-tags* Start and End Tags ~ By default the start and end tags are set to be '<{' and '}>'. These can be changed by setting the following variables in vimrc: > g:snip_start_tag g:snip_end_tag They can be also changed for a specific buffer by setting the following: > b:snip_start_tag b:snip_end_tag ~ *snip-elem-delimiter* Element Delimiter ~ The value of snip_elem_delim is used to separate a tag's name and its command. By default it is set to ':' but can be set as above either globally or for a specific buffer using the following variables: > g:snip_elem_delim b:snip_elem_delim ~ *snip-remap-key* Remapping the default jump key ~ The trigger key is mapped to Tab by default. Some people may wish to remap this if it causes conflicts with other plugins. The key can be set in your <.vimrc> by setting the 'g:snippetsEmu_key' variable. An example > let g:snippetsEmu_key = "" Snippets will now be triggered by Shift-Tab rather than just Tab. NB, this example may not work in all terminals as some trap Shift-Tab before it gets to Vim. ~ ============================================================================== DETAILED EXPLANATIONS *snip-detailed-explanations* *snip-tag-name-syntax* Valid Tag Names ~ Tag names cannot contain whitespace unless they are enclosed in quotes. Valid Examples: > <{validName}> <{"valid name"}> <{tagName:command}> <{"Tag Name":command}> Invalid Examples: > <{invalid name}> <{Tag Name:command}> <{:command}> ~ *snip-advanced-tag-commands* Advanced Tag Command Examples ~ Commands in tags can be as complex as desired. Readability is the main limitation as the command will be placed in the document before execution. The preferred method for defining complex commands is to hide the functionality in a user function. Example: > function! Count(haystack, needle) let counter = 0 let index = match(a:haystack, a:needle) while index > -1 let counter = counter + 1 let index = match(a:haystack, a:needle, index+1) endwhile return counter endfunction function! PyArgList(count) if a:count == 0 return "(,)" else return '('.repeat('<{}>, ', a:count).')' endif endfunction Snippet pf print "<{s}>" % <{s:PyArgList(Count(@z, '%[^%]'))}><{}> The above snippet will expand 'pf' to 'print "<{s}>" ...'. The user then enters a format string. Once the string is entered the Count and PyArgList functions are used to generate a number of empty tags. *snip-limitations* The above represents once of the limitations of the plugin. Due to the way tags are identified it is not possible to include empty tags in another tag's command. The only way to generate empty tags is to return them from a function as in the above example. For other examples see the included bundles. *snip-bundles* The included bundles are not defined in the 'preferred style'. In order to accommodate users who wish to redefine the default tags all snippet definitions are 'executed' with the 'exec' command. E.g. > exec "Snippet test This isn't the right way to ".st.et." define snippets" Executing the command allows 'st' and 'et' to be used in place of start and end tags. 'st' and 'et' are defined elsewhere in the bundle file. ============================================================================== SNIPPETSEMU CONTACT DETAILS *snip-contact-details* To contact the author please email: F Ingram lists gmail com The author welcomes corrections to this documentation, example snippets and bug reports. The plugin is also currently hosted at Google Code: http://code.google.com/p/snippetsemu Bug reports can also be posted on the hosting site: http://code.google.com/p/snippetsemu/issues/list *snip-contributors* Contributors to SnippetsEmu ~ Patches: Ori Avtalion - Improvements to Snippet command Freddy Vulto - Improved behaviour Andy Block - Bug with commands on same line. This is why I should do better test suites. bzklrm - Removal of some normal commands Priit Tamboom - Sorting out left and right mappings Documentation: Panos Laganakos - Greek translation (coming soon) Bundles: Panos Laganakos - Python snippets Alex Pounds - Django snippets Chris Lasher - Python snippets knipknap - Python snippets James Widman - C snippets ============================================================================== SNIPPETSEMU KNOWN BUGS *snippets_emu-bugs* Bugs are currently tracked on Google Code. Please post any you find on the issue tracker: http://code.google.com/p/snippetsemu/issues/list ============================================================================== SNIPPETSEMU TROUBLESHOOTING *snippets_emu-troubleshooting* Problem: Bundles are not loading. Answer: Ensure that you have filetype plugins turned on. Include the following in your vimrc: > filetype plugin on vim:tw=78:sw=4:ts=8:ft=help:norl: work/snippetsEmu/plugin/0000775000000000000000000000000014775444730012561 5ustar work/snippetsEmu/plugin/snippetsEmu.vim0000664000000000000000000010213114775444730015610 0ustar " File: snippetsEmu.vim " Author: Felix Ingram " ( f.ingram.lists gmail.com ) " Description: An attempt to implement TextMate style Snippets. Features include " automatic cursor placement and command execution. " $LastChangedDate$ " Version: 1.1 " $Revision$ " " This file contains some simple functions that attempt to emulate some of the " behaviour of 'Snippets' from the OS X editor TextMate, in particular the " variable bouncing and replacement behaviour. " " {{{ USAGE: " " Place the file in your plugin directory. " Define snippets using the Snippet command. " Snippets are best defined in the 'after' subdirectory of your Vim home " directory ('~/.vim/after' on Unix). Filetype specific snippets can be defined " in '~/.vim/after/ftplugin/_snippets.vim. Using the argument will " By default snippets are buffer specific. To define general snippets available " globally use the 'Iabbr' command. " " Example One: " Snippet fori for <{datum}> in <{data}>:<{datum}>.<{}> " " The above will expand to the following (indenting may differ): " " for <{datum}> in <{data}>: " <{datum}>.<{}> " " The cursor will be placed after the first '<{' in insert mode. " Pressing will 'tab' to the next place marker (<{data}>) in " insert mode. Adding text between <{ and }> and then hitting <{Tab}> will " remove the angle brackets and replace all markers with a similar identifier. " " Example Two: " With the cursor at the pipe, hitting will replace: " for <{MyVariableName|datum}> in <{data}>: " <{datum}>.<{}> " " with (the pipe shows the cursor placement): " " for MyVariableName in <{data}>: " MyVariableName.<{}> " " Enjoy. " " For more information please see the documentation accompanying this plugin. " " Additional Features: " " Commands in tags. Anything after a ':' in a tag will be run with Vim's " 'execute' command. The value entered by the user (or the tag name if no change " has been made) is passed in the @z register (the original contents of the " register are restored once the command has been run). " " Named Tags. Naming a tag (the <{datum}> tag in the example above) and changing " the value will cause all other tags with the same name to be changed to the " same value (as illustrated in the above example). Not changing the value and " hitting will cause the tag's name to be used as the default value. " " Test tags for pattern matching: " The following are examples of valid and invalid tags. Whitespace can only be " used in a tag name if the name is enclosed in quotes. " " Valid tags " <{}> " <{tagName}> " <{tagName:command}> " <{"Tag Name"}> " <{"Tag Name":command}> " " Invalid tags, random text " <{:}> " <{:command}> " <{Tag Name}> " <{Tag Name:command}> " <{"Tag Name":}> " <{Tag }> " <{OpenTag " " Here's our magic search term (assumes '<{',':' and '}>' as our tag delimiters: " <{\([^[:punct:] \t]\{-}\|".\{-}"\)\(:[^}>]\{-1,}\)\?}> " }}} if v:version < 700 echomsg "snippetsEmu plugin requires Vim version 7 or later" finish endif if globpath(&rtp, 'plugin/snippetEmu.vim') != "" call confirm("It looks like you've got an old version of snippetsEmu installed. Please delete the file 'snippetEmu.vim' from the plugin directory. Note lack of 's'") endif let s:debug = 0 let s:Disable = 0 function! s:Debug(func, text) if exists('s:debug') && s:debug == 1 echom "Snippy: ".a:func.": ".a:text endif endfunction if (exists('loaded_snippet') || &cp) && !s:debug finish endif "call s:Debug("","Started the plugin") let loaded_snippet=1 " {{{ Set up variables if !exists("g:snip_start_tag") let g:snip_start_tag = "<{" endif if !exists("g:snip_end_tag") let g:snip_end_tag = "}>" endif if !exists("g:snip_elem_delim") let g:snip_elem_delim = ":" endif if !exists("g:snippetsEmu_key") let g:snippetsEmu_key = "" endif "call s:Debug("", "Set variables") " }}} " {{{ Set up menu for def_file in split(globpath(&rtp, "after/ftplugin/*_snippets.vim"), '\n') "call s:Debug("","Adding ".def_file." definitions to menu") let snip = substitute(def_file, '.*[\\/]\(.*\)_snippets.vim', '\1', '') exec "nmenu S&nippets.".snip." :source ".def_file."" endfor " }}} " {{{ Sort out supertab function! s:GetSuperTabSNR() let a_sav = @a redir @a exec "silent function" redir END let funclist = @a let @a = a_sav try let func = split(split(matchstr(funclist,'.SNR.\{-}SuperTab(command)'),'\n')[-1])[1] return matchlist(func, '\(.*\)S')[1] catch /E684/ endtry return "" endfunction function! s:SetupSupertab() if !exists('s:supInstalled') let s:supInstalled = 0 endif if s:supInstalled == 1 || globpath(&rtp, 'plugin/supertab.vim') != "" "call s:Debug("SetupSupertab", "Supertab installed") let s:SupSNR = s:GetSuperTabSNR() let s:supInstalled = 1 if s:SupSNR != "" let s:done_remap = 1 else let s:done_remap = 0 endif endif endfunction call s:SetupSupertab() " }}} " {{{ Map Jumper to the default key if not set already function! s:SnipMapKeys() if (!hasmapto('Jumper','i')) if s:supInstalled == 1 exec 'imap '.g:snippetsEmu_key.' Jumper' else exec 'imap '.g:snippetsEmu_key.' Jumper' endif endif if (!hasmapto( 'i'.g:snippetsEmu_key, 's')) exec 'smap '.g:snippetsEmu_key.' i'.g:snippetsEmu_key endif imap