From 1ef6705fdb593b0b606a477912d9e9556b34dfb8 Mon Sep 17 00:00:00 2001 From: stefan Date: Thu, 30 Oct 2008 08:14:42 +0000 Subject: [PATCH] GetLatestVimscripts git-svn-id: https://vimsuite.svn.sourceforge.net/svnroot/vimsuite/trunk@171 eb2d0018-73a3-4aeb-bfe9-1def61c9ec69 --- vimfiles/autoload/Align.vim | 2021 ++++++++-------- vimfiles/autoload/AlignMaps.vim | 330 +++ vimfiles/autoload/netrw.vim | 576 +++-- vimfiles/autoload/netrwFileHandlers.vim | 716 +++--- vimfiles/autoload/netrwSettings.vim | 8 +- vimfiles/doc/Align.txt | 2801 ++++++++++++----------- vimfiles/doc/pi_netrw.txt | 167 +- vimfiles/doc/tags | 8 +- vimfiles/plugin/AlignMaps.vim | 506 ---- vimfiles/plugin/AlignMapsPlugin.vim | 230 ++ vimfiles/plugin/DirDiff.vim | 25 +- vimfiles/plugin/cecutil.vim | 134 +- vimfiles/plugin/netrwPlugin.vim | 11 +- vimfiles/syntax/netrw.vim | 2 +- 14 files changed, 3959 insertions(+), 3576 deletions(-) create mode 100644 vimfiles/autoload/AlignMaps.vim delete mode 100644 vimfiles/plugin/AlignMaps.vim create mode 100644 vimfiles/plugin/AlignMapsPlugin.vim diff --git a/vimfiles/autoload/Align.vim b/vimfiles/autoload/Align.vim index 66751bd..9c61728 100644 --- a/vimfiles/autoload/Align.vim +++ b/vimfiles/autoload/Align.vim @@ -1,1007 +1,1014 @@ -" Align: tool to align multiple fields based on one or more separators -" Author: Charles E. Campbell, Jr. -" Date: Mar 06, 2008 -" Version: 33 -" GetLatestVimScripts: 294 1 :AutoInstall: Align.vim -" GetLatestVimScripts: 1066 1 :AutoInstall: cecutil.vim -" Copyright: Copyright (C) 1999-2007 Charles E. Campbell, Jr. {{{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. - -" --------------------------------------------------------------------- -" Load Once: {{{1 -if exists("g:loaded_align") || &cp - finish -endif -let g:loaded_align = "v33" -let s:keepcpo = &cpo -set cpo&vim -"DechoTabOn - -" --------------------------------------------------------------------- -" Debugging Support: -"if !exists("g:loaded_Decho") "Decho -" runtime plugin/Decho.vim -"endif " Decho - -" --------------------------------------------------------------------- -" 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("AlignCtrl(...) a:0=".a:0) - - " save options that will be changed - let keep_search = @/ - let keep_ic = &ic - - " turn ignorecase off - set 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" - let &ic= keep_ic -" call Dret("AlignCtrl") - return - endif - let ipat= ipat + 1 - endwhile - endif - endif - -" 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 - " ---------------------- - echo "AlignCtrl<".s:AlignCtrl."> qty=".s:AlignPatQty." AlignStyle<".s:AlignStyle."> Padding<".s:AlignPrePad."|".s:AlignPostPad."> LeadingWS=".s:AlignLeadKeep." AlignSep=".s:AlignSep -" call Decho("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("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 - let &ic = keep_ic - let @/ = keep_search -" call Dret("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 =~# "=" -" 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' -" 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' - let @/ = keep_search - let &ic= keep_ic -" call Dret("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' - let @/ = keep_search - let &ic= keep_ic -" call Dret("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 w: 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:AlignGPat") - unlet s:AlignGPat -" 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:AlignVPat") - unlet s:AlignVPat -" 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 search and options - let @/ = keep_search - let &ic= keep_ic - -" call Dret("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 - -" --------------------------------------------------------------------- -" 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 check - 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 - - " 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 Dret("Align#Align") - return - endif - let ipat= ipat + 1 - endwhile - - " record current search pattern for subsequent restoration - let keep_search= @/ - let keep_ic = &ic - let keep_report= &report - set noic report=10000 - - 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 -" 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 == "\" - if exists("g:Align_xstrlen") && g:Align_xstrlen - let ragged = ( col("'>") > s:Strlen(getline("'>")) || col("'<") > s:Strlen(getline("'<")) ) - else - let ragged = ( col("'>") > strlen(getline("'>")) || col("'<") > strlen(getline("'<")) ) - endif - 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.">") - - " Keep user options - let etkeep = &et - let pastekeep= &paste - setlocal et 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','') -" call Decho("retaining 1st leading whitespace: bgntxt<".bgntxt.">") - set noet - endif - exe begline.",".endline."ret" - - " 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 line= begline - while line <= endline - " Process each line - let txt = getline(line) -" call Decho(" ") -" call Decho("Pass".pass.": Line ".line." <".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 line= line + 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 line= line + 1 - continue - endif - endif - - " Always skip blank lines - if match(txt,'^\s*$') != -1 -" call Decho("Pass".pass.": skipping") - let line= line + 1 - continue - endif - - " Extract visual-block selected text (init bgntxt, endtxt) - if exists("g:Align_xstrlen") && g:Align_xstrlen - let txtlen= s:Strlen(txt) - else - let txtlen= strlen(txt) - endif - 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 "no separators specified!"|echohl None -" 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 - - " cylic 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. - " Extend field if alignop is '-' - 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) - 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 - if exists("g:Align_xstrlen") && g:Align_xstrlen - let fieldlen = s:Strlen(field) - else - let fieldlen = strlen(field) - endif - let sFieldSize = "FieldSize_".ifield - if !exists(sFieldSize) - let FieldSize_{ifield}= fieldlen -" call Decho("Pass".pass.": set FieldSize_{".ifield."}=".FieldSize_{ifield}." <".field.">") - elseif fieldlen > FieldSize_{ifield} - let FieldSize_{ifield}= fieldlen -" call Decho("Pass".pass.": oset FieldSize_{".ifield."}=".FieldSize_{ifield}." <".field.">") - endif - let sSepSize= "SepSize_".ifield - if !exists(sSepSize) - let SepSize_{ifield}= seplen -" call Decho(" set SepSize_{".ifield."}=".SepSize_{ifield}." <".field.">") - elseif seplen > SepSize_{ifield} - let SepSize_{ifield}= seplen -" call Decho("Pass".pass.": oset SepSize_{".ifield."}=".SepSize_{ifield}." <".field.">") - 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','') - if s:AlignLeadKeep == 'W' - let field = bgntxt.field - let bgntxt= "" - endif - if doend == 2 - let prepad = 0 - let postpad= 0 - endif - if exists("g:Align_xstrlen") && g:Align_xstrlen - let fieldlen = s:Strlen(field) - else - let fieldlen = strlen(field) - endif - let sep = s:MakeSpace(prepad).strpart(txt,endfield,sepfield-endfield).s:MakeSpace(postpad) - if seplen < SepSize_{ifield} - if alignsepop == "<" - " left-justify separators - let sep = sep.s:MakeSpace(SepSize_{ifield}-seplen) - elseif alignsepop == ">" - " right-justify separators - let sep = s:MakeSpace(SepSize_{ifield}-seplen).sep - 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) - endif - endif - let spaces = FieldSize_{ifield} - fieldlen -" 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."> line=".line) -" call Decho("Pass".pass.": newtxt<".newtxt.">") -" call Decho("Pass".pass.": endtxt<".endtxt.">") - call setline(line,bgntxt.newtxt.endtxt) - endif - - let line = line + 1 - endwhile " line loop - - let pass= pass + 1 - endwhile " pass loop -" call Decho("end of two pass loop") - - " Restore user options - let &et = etkeep - let &paste = pastekeep - - if exists("s:DoAlignPop") - " AlignCtrl Map support - call Align#AlignPop() - unlet s:DoAlignPop - endif - - " restore current search pattern - let @/ = keep_search - let &ic = keep_ic - let &report = keep_report - -" call Dret("Align#Align") - return -endfun - -" --------------------------------------------------------------------- -" AlignPush: this command/function pushes an alignment control string onto a stack {{{1 -fun! Align#AlignPush() -" call Dfunc("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("AlignPush") -endfun - -" --------------------------------------------------------------------- -" 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 "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 "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 - -" --------------------------------------------------------------------- -" AlignReplaceQuotedSpaces: {{{1 -fun! Align#AlignReplaceQuotedSpaces() -" call Dfunc("AlignReplaceQuotedSpaces()") - - let l:line = getline(line(".")) - if exists("g:Align_xstrlen") && g:Align_xstrlen - let l:linelen = s:Strlen(l:line) - else - let l:linelen = strlen(l:line) - endif - 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 '"' - 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 - - else - " split at all whitespace - let qarglist= split(a:qarg) - 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. Depends on virtcol(). -" 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.">") - if 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= &mod - exe "norm! o\" - call setline(line("."),a:x) - let ret= virtcol("$") - 1 - d - let &mod= modkeep - - else - " at least give a decent default - ret= strlen(a:x) - endif -" call Dret("s:Strlen ".ret) - return ret -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 +" Align: tool to align multiple fields based on one or more separators +" Author: Charles E. Campbell, Jr. +" Date: Oct 08, 2008 +" Version: 34 +" GetLatestVimScripts: 294 1 :AutoInstall: Align.vim +" GetLatestVimScripts: 1066 1 :AutoInstall: cecutil.vim +" Copyright: Copyright (C) 1999-2007 Charles E. Campbell, Jr. {{{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. + +" --------------------------------------------------------------------- +" Load Once: {{{1 +if exists("g:loaded_align") || &cp + finish +endif +let g:loaded_align = "v34" +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: +"if !exists("g:loaded_Decho") | runtime plugin/Decho.vim | 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("AlignCtrl(...) a:0=".a:0) + + " save options that will be changed + let keep_search = @/ + let keep_ic = &ic + + " turn ignorecase off + set 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" + let &ic= keep_ic +" call Dret("AlignCtrl") + return + endif + let ipat= ipat + 1 + endwhile + endif + endif + +" 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<".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("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 + let &ic = keep_ic + let @/ = keep_search +" call Dret("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 =~# "=" +" 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' +" 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' + let @/ = keep_search + let &ic= keep_ic +" call Dret("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' + let @/ = keep_search + let &ic= keep_ic +" call Dret("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 w: 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:AlignGPat") + unlet s:AlignGPat +" 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:AlignVPat") + unlet s:AlignVPat +" 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 search and options + let @/ = keep_search + let &ic= keep_ic + +" call Dret("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 check + 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 + + " 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 Dret("Align#Align") + return + endif + let ipat= ipat + 1 + endwhile + + " record current search pattern for subsequent restoration + let keep_search= @/ + let keep_ic = &ic + let keep_report= &report + set noic report=10000 + + 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 +" 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 == "\" + if exists("g:Align_xstrlen") && g:Align_xstrlen + let ragged = ( col("'>") > s:Strlen(getline("'>")) || col("'<") > s:Strlen(getline("'<")) ) + else + let ragged = ( col("'>") > strlen(getline("'>")) || col("'<") > strlen(getline("'<")) ) + endif + 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.">") + + " Keep user options + let etkeep = &l:et + let pastekeep= &l:paste + setlocal et 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','') +" call Decho("retaining 1st leading whitespace: bgntxt<".bgntxt.">") + set noet + endif + exe begline.",".endline."ret" + + " 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 line= begline + while line <= endline + " Process each line + let txt = getline(line) +" call Decho(" ") +" call Decho("Pass".pass.": Line ".line." <".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 line= line + 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 line= line + 1 + continue + endif + endif + + " Always skip blank lines + if match(txt,'^\s*$') != -1 +" call Decho("Pass".pass.": skipping") + let line= line + 1 + continue + endif + + " Extract visual-block selected text (init bgntxt, endtxt) + if exists("g:Align_xstrlen") && g:Align_xstrlen + let txtlen= s:Strlen(txt) + else + let txtlen= strlen(txt) + endif + 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 "no separators specified!"|echohl None +" 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 + + " cylic 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. + " Extend field if alignop is '-' + 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) + 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 + if exists("g:Align_xstrlen") && g:Align_xstrlen + let fieldlen = s:Strlen(field) + else + let fieldlen = strlen(field) + endif + let sFieldSize = "FieldSize_".ifield + if !exists(sFieldSize) + let FieldSize_{ifield}= fieldlen +" call Decho("Pass".pass.": set FieldSize_{".ifield."}=".FieldSize_{ifield}." <".field.">") + elseif fieldlen > FieldSize_{ifield} + let FieldSize_{ifield}= fieldlen +" call Decho("Pass".pass.": oset FieldSize_{".ifield."}=".FieldSize_{ifield}." <".field.">") + endif + let sSepSize= "SepSize_".ifield + if !exists(sSepSize) + let SepSize_{ifield}= seplen +" call Decho(" set SepSize_{".ifield."}=".SepSize_{ifield}." <".field.">") + elseif seplen > SepSize_{ifield} + let SepSize_{ifield}= seplen +" call Decho("Pass".pass.": oset SepSize_{".ifield."}=".SepSize_{ifield}." <".field.">") + 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','') + if s:AlignLeadKeep == 'W' + let field = bgntxt.field + let bgntxt= "" + endif + if doend == 2 + let prepad = 0 + let postpad= 0 + endif + if exists("g:Align_xstrlen") && g:Align_xstrlen + let fieldlen = s:Strlen(field) + else + let fieldlen = strlen(field) + endif + let sep = s:MakeSpace(prepad).strpart(txt,endfield,sepfield-endfield).s:MakeSpace(postpad) + if seplen < SepSize_{ifield} + if alignsepop == "<" + " left-justify separators + let sep = sep.s:MakeSpace(SepSize_{ifield}-seplen) + elseif alignsepop == ">" + " right-justify separators + let sep = s:MakeSpace(SepSize_{ifield}-seplen).sep + 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) + endif + endif + let spaces = FieldSize_{ifield} - fieldlen +" 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."> line=".line) +" call Decho("Pass".pass.": newtxt<".newtxt.">") +" call Decho("Pass".pass.": endtxt<".endtxt.">") + call setline(line,bgntxt.newtxt.endtxt) + endif + + let line = line + 1 + endwhile " line loop + + let pass= pass + 1 + endwhile " pass loop +" call Decho("end of two pass loop") + + " Restore user options + let &l:et = etkeep + let &l:paste = pastekeep + + if exists("s:DoAlignPop") + " AlignCtrl Map support + call Align#AlignPop() + unlet s:DoAlignPop + endif + + " restore current search pattern + let @/ = keep_search + let &ic = keep_ic + let &report = keep_report + +" 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("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("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 "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 "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("AlignReplaceQuotedSpaces()") + + let l:line = getline(line(".")) + if exists("g:Align_xstrlen") && g:Align_xstrlen + let l:linelen = s:Strlen(l:line) + else + let l:linelen = strlen(l:line) + endif + 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 '"' + 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 + + else + " split at all whitespace + let qarglist= split(a:qarg) + 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.">") + if 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= &mod + exe "norm! o\" + call setline(line("."),a:x) + let ret= virtcol("$") - 1 + d + let &mod= modkeep + + else + " at least give a decent default + ret= strlen(a:x) + endif +" call Dret("s:Strlen ".ret) + return ret +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 diff --git a/vimfiles/autoload/AlignMaps.vim b/vimfiles/autoload/AlignMaps.vim new file mode 100644 index 0000000..3246afb --- /dev/null +++ b/vimfiles/autoload/AlignMaps.vim @@ -0,0 +1,330 @@ +" AlignMaps.vim : support functions for AlignMaps +" Author: Charles E. Campbell, Jr. +" Date: Oct 24, 2008 +" Version: 40 +" --------------------------------------------------------------------- +" Load Once: {{{1 +if &cp || exists("g:loaded_AlignMaps") + finish +endif +let g:loaded_AlignMaps= "v40" +let s:keepcpo = &cpo +set cpo&vim + +" ===================================================================== +" Functions: {{{1 + +" --------------------------------------------------------------------- +" AlignMaps#WrapperStart: {{{2 +fun! AlignMaps#WrapperStart(vis) +" call Dfunc("AlignMaps#WrapperStart(vis=".a:vis.")") + + if a:vis + 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 ='' + norm! mz'a + put! ='' + ky + let s:alignmaps_zline = line("'z") + exe "'y,'zs/@/\177/ge" + else +" call Decho("embedded wrapper") + let s:alignmaps_wrapcnt = s:alignmaps_wrapcnt + 1 + norm! 'yjma'zk + endif + + " change some settings to align-standard values + set nogd + set ch=2 + AlignPush + norm! 'zk +" call Dret("AlignMaps#WrapperStart : alignmaps_wrapcnt=".s:alignmaps_wrapcnt." my=".line("'y")." mz=".line("'z")) +endfun + +" --------------------------------------------------------------------- +" AlignMaps#WrapperEnd: {{{2 +fun! AlignMaps#WrapperEnd() +" 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 + 'y,'zs/ \+$//e + + " restore AlignCtrl settings + AlignPop + + let s:alignmaps_wrapcnt= s:alignmaps_wrapcnt - 1 + if s:alignmaps_wrapcnt <= 0 + " initial wrapper ending + exe "'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 + 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#StdAlign: some semi-standard align calls {{{2 +fun! AlignMaps#StdAlign(mode) +" 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 + norm! 'a + while match(getline(aline),a:chr . "\s*$") != -1 && rep >= 0 + " while = at end-of-line, delete it and join with next + 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 + norm! jma + let aline = line("'a") + endwhile +" call Dret("AlignMaps#CharJoiner") +endfun + +" --------------------------------------------------------------------- +" AlignMaps#Equals: supports \t= and \T= {{{2 +fun! AlignMaps#Equals() +" call Dfunc("AlignMaps#Equals()") + 'a,'zs/\s\+\([*/+\-%|&\~^]\==\)/ \1/e + 'a,'zs@ \+\([*/+\-%|&\~^]\)=@\1=@ge + 'a,'zs/==/\="\\"/ge + 'a,'zs/!=/\="!\"/ge + norm g'zk + AlignCtrl mIp1P1=l = + AlignCtrl g = + 'a,'z-1Align + 'a,'z-1s@\([*/+\-%|&\~^!=]\)\( \+\)=@\2\1=@ge + 'a,'z-1s/\( \+\);/;\1/ge + if &ft == "c" || &ft == "cpp" +" call Decho("exception for ".&ft) + 'a,'z-1v/^\s*\/[*/]/s/\/[*/]/@&@/e + 'a,'z-1v/^\s*\/[*/]/s/\*\//@&/e + if exists("g:mapleader") + exe "norm 'zk" + call AlignMaps#StdAlign(1) + else + exe "norm 'zk" + call AlignMaps#StdAlign(1) + endif + 'y,'zs/^\(\s*\) @/\1/e + endif + 'a,'z-1s/\%xff/=/ge + '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 = &ch + let gdkeep = &gd + let vekeep = &ve + set ch=2 nogd ve= + + " 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 "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 + norm! %my + s/(\s*\(\S\)/(\r \1/e + exe "norm! `y%" + s/)\s*\(\/[*/]\)/)\r\1/e + exe "norm! `y%mz" + 'y,'zs/\s\+$//e + 'y,'zs/^\s\+//e + 'y+1,'zs/^/ / + + " insert newline after every comma only one parenthesis deep + sil! exe "norm! `y\h" + let parens = 1 + let cmmnt = 0 + let cmmntline= -1 + while parens >= 1 +" call Decho("parens=".parens." @a=".@a) + exe 'norm! ma "ay`a ' + 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 "norm! i\\" + endif + endwhile + norm! `y%mz% + sil! 'y,'zg/^\s*$/d + + " perform substitutes to mark fields for Align + sil! 'y+1,'zv/^\//s/^\s\+\(\S\)/ \1/e + sil! 'y+1,'zv/^\//s/\(\S\)\s\+/\1 /eg + sil! 'y+1,'zv/^\//s/\* \+/*/ge + sil! 'y+1,'zv/^\//s/\w\zs\s*\*/ */ge + " func + " ws <- declaration -> <-ptr -> <-var-> <-[array][] -> <-glop-> <-end-> + sil! 'y+1,'zv/^\//s/^\s*\(\(\K\k*\s*\)\+\)\s\+\([(*]*\)\s*\(\K\k*\)\s*\(\(\[.\{-}]\)*\)\s*\(.\{-}\)\=\s*\([,)]\)\s*$/ \1@#\3@\4\5@\7\8/e + sil! 'y+1,'z+1g/^\s*\/[*/]/norm! kJ + sil! 'y+1,'z+1s%/[*/]%@&@%ge + sil! 'y+1,'z+1s%*/%@&%ge + AlignCtrl mIp0P0=l @ + sil! 'y+1,'zAlign + sil! 'y,'zs%@\(/[*/]\)@%\t\1 %e + sil! 'y,'zs%@\*/% */%e + sil! 'y,'zs/@\([,)]\)/\1/ + sil! 'y,'zs/@/ / + AlignCtrl mIlrp0P0= # @ + sil! 'y+1,'zAlign + sil! 'y+1,'zs/#/ / + sil! 'y+1,'zs/@// + sil! 'y+1,'zs/\(\s\+\)\([,)]\)/\2\1/e + + " Restore + call RestoreMark(mykeep) + call RestoreMark(mzkeep) + let &ch= chkeep + let &gd= gdkeep + let &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.">") + + " Get the type. I'm assuming one type per line (ie. int x; double y; on one line will not be handled properly) + let @x=substitute(curline,'^\(\s*[a-zA-Z_ \t][a-zA-Z0-9_ \t]*\)\s\+[(*]*\h.*$','\1','') +" call Decho("@x<".@x.">") + + " transform line + exe 's/,/;\r'.@x.' /ge' + + "restore register x + let @x= xkeep + +" call Dret("AlignMaps#FixMultiDec : my=".line("'y")." mz=".line("'z")) +endfun + +" --------------------------------------------------------------------- +" Restore: {{{1 +let &cpo= s:keepcpo +unlet s:keepcpo +" vim: ts=4 fdm=marker diff --git a/vimfiles/autoload/netrw.vim b/vimfiles/autoload/netrw.vim index 1f7ef38..0bd0283 100644 --- a/vimfiles/autoload/netrw.vim +++ b/vimfiles/autoload/netrw.vim @@ -1,7 +1,7 @@ " netrw.vim: Handles file transfer and remote directory listing across " AUTOLOAD SECTION -" Date: Sep 02, 2008 -" Version: 133 +" Date: Oct 23, 2008 +" Version: 134 " Maintainer: Charles E Campbell, Jr " GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim " Copyright: Copyright (C) 1999-2008 Charles E. Campbell, Jr. {{{1 @@ -22,12 +22,18 @@ if &cp || exists("g:loaded_netrw") finish endif +let g:loaded_netrw = "v134" +if v:version < 702 + echohl WarningMsg + echo "***warning*** this version of netrw needs vim 7.2" + echohl Normal + finish +endif if !exists("s:NOTE") let s:NOTE = 0 let s:WARNING = 1 let s:ERROR = 2 endif -let g:loaded_netrw = "v133" " sanity checks if v:version < 700 @@ -46,11 +52,8 @@ setlocal cpo&vim " --------------------------------------------------------------------- " Netrw Constants: {{{2 -if !exists("g:NETRW_BOOKMARKMAX") - let g:NETRW_BOOKMARKMAX= 0 -endif -if !exists("g:NETRW_DIRHIST_CNT") - let g:NETRW_DIRHIST_CNT= 0 +if !exists("g:netrw_dirhist_cnt") + let g:netrw_dirhist_cnt= 0 endif if !exists("s:LONGLIST") let s:THINLIST = 0 @@ -63,7 +66,13 @@ endif " --------------------------------------------------------------------- " Default values for netrw's global protocol variables {{{2 if !exists("g:netrw_dav_cmd") + if executable("cadaver") let g:netrw_dav_cmd = "cadaver" + elseif executable("curl") + let g:netrw_dav_cmd = "curl" + else + let g:netrw_dav_cmd = "" + endif endif if !exists("g:netrw_fetch_cmd") if executable("fetch") @@ -78,16 +87,29 @@ endif if !exists("g:netrw_http_cmd") if executable("elinks") let g:netrw_http_cmd = "elinks" - let g:netrw_http_xcmd= "-dump >" + if !exists("g:netrw_http_xcmd") + let g:netrw_http_xcmd= "-dump >" + endif elseif executable("links") let g:netrw_http_cmd = "links" - let g:netrw_http_xcmd= "-dump >" + if !exists("g:netrw_http_xcmd") + let g:netrw_http_xcmd= "-dump >" + endif elseif executable("curl") - let g:netrw_http_cmd = "curl -o" + let g:netrw_http_cmd = "curl" + if !exists("g:netrw_http_xcmd") + let g:netrw_http_xcmd= "-o" + endif elseif executable("wget") - let g:netrw_http_cmd = "wget -q -O" + let g:netrw_http_cmd = "wget" + if !exists("g:netrw_http_xcmd") + let g:netrw_http_xcmd= "-q -O" + endif elseif executable("fetch") - let g:netrw_http_cmd = "fetch -o" + let g:netrw_http_cmd = "fetch" + if !exists("g:netrw_http_xcmd") + let g:netrw_http_xcmd= "-o" + endif else let g:netrw_http_cmd = "" endif @@ -158,8 +180,8 @@ if !exists("g:netrw_cursorline") let s:netrw_usercuc = &cursorcolumn endif " Default values - d-g ---------- {{{3 -if !exists("g:NETRW_DIRHIST_CNT") - let g:NETRW_DIRHIST_CNT= 0 +if !exists("g:netrw_dirhist_cnt") + let g:netrw_dirhist_cnt= 0 endif if !exists("g:netrw_decompress") let g:netrw_decompress= { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf"} @@ -518,6 +540,7 @@ fun! s:NetrwSafeOptions() setlocal fo=nroql2 setlocal tw=0 setlocal report=10000 + setlocal isk+=@ isk+=* isk+=/ if g:netrw_use_noswf && has("win32") && !has("win95") setlocal noswf endif @@ -873,28 +896,38 @@ fun! netrw#NetRead(mode,...) setlocal ro "......................................... - " cadaver: NetRead Method #6 {{{3 + " dav: NetRead Method #6 {{{3 elseif b:netrw_method == 6 " call Decho("read via cadaver (method #6)") - " Construct execution string (four lines) which will be passed through filter - let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) - new - setlocal ff=unix - if exists("g:netrw_port") && g:netrw_port != "" - put ='open '.g:netrw_machine.' '.g:netrw_port - else - put ='open '.g:netrw_machine + if !executable(g:netrw_dav_cmd) + call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73) +" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable") + return endif - put ='user '.g:netrw_uid.' '.s:netrw_passwd - put ='get '.netrw_fname.' '.tmpfile - put ='quit' + if g:netrw_dav_cmd =~ "curl" +" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_dav_cmd." ".shellescape("dav://".g:netrw_machine.b:netrw_fname,1)." ".shellescape(tmpfile,1)) + exe s:netrw_silentxfer."!".g:netrw_dav_cmd." ".shellescape("dav://".g:netrw_machine.b:netrw_fname,1)." ".shellescape(tmpfile,1) + else + " Construct execution string (four lines) which will be passed through filter + let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) + new + setlocal ff=unix + if exists("g:netrw_port") && g:netrw_port != "" + put ='open '.g:netrw_machine.' '.g:netrw_port + else + put ='open '.g:netrw_machine + endif + put ='user '.g:netrw_uid.' '.s:netrw_passwd + put ='get '.netrw_fname.' '.tmpfile + put ='quit' - " perform cadaver operation: - norm! 1Gdd + " perform cadaver operation: + norm! 1Gdd " call Decho("executing: %!".g:netrw_dav_cmd) - exe s:netrw_silentxfer."%!".g:netrw_dav_cmd - bd! + exe s:netrw_silentxfer."%!".g:netrw_dav_cmd + bd! + endif let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) let b:netrw_lastfile = choice @@ -1444,7 +1477,7 @@ endfun " 3: ftp + machine, id, password, and [path]filename " 4: scp " 5: http (wget) -" 6: cadaver +" 6: dav " 7: rsync " 8: fetch " 9: sftp @@ -1479,7 +1512,7 @@ fun! s:NetrwMethod(choice) " rcphf : [user@]host:filename Use rcp " scpurm : scp://[user@]host[[#:]port]/filename Use scp " httpurm : http://[user@]host/filename Use wget - " davurm : dav[s]://host[:port]/path Use cadaver + " davurm : dav[s]://host[:port]/path Use cadaver/curl " rsyncurm : rsync://host[:port]/path Use rsync " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http) " sftpurm : sftp://[user@]host/filename Use scp @@ -1726,7 +1759,7 @@ fun! s:BrowserMaps(islocal) nnoremap :call netrw#LocalBrowseCheck(NetrwBrowseChgDir(1,NetrwGetWord())) nnoremap - :exe "norm! 0"call netrw#LocalBrowseCheck(NetrwBrowseChgDir(1,'../')) nnoremap a :call NetrwHide(1) - nnoremap mb :call NetrwBookmarkDir(0,b:netrw_curdir) + nnoremap mb :call NetrwBookHistHandler(0,b:netrw_curdir) nnoremap mc :call NetrwMarkFileCopy(1) nnoremap md :call NetrwMarkFileDiff(1) nnoremap me :call NetrwMarkFileEdit(1) @@ -1742,7 +1775,7 @@ fun! s:BrowserMaps(islocal) nnoremap mu :call NetrwUnMarkFile(1) nnoremap mx :call NetrwMarkFileExe(1) nnoremap mz :call NetrwMarkFileCompress(1) - nnoremap gb :call NetrwBookmarkDir(1,b:netrw_curdir) + nnoremap gb :call NetrwBookHistHandler(1,b:netrw_curdir) nnoremap gh :call NetrwHidden(1) nnoremap c :exe "keepjumps lcd ".fnameescape(b:netrw_curdir) nnoremap C :let g:netrw_chgwin= winnr() @@ -1752,15 +1785,15 @@ fun! s:BrowserMaps(islocal) nnoremap O :call NetrwObtain(1) nnoremap p :call NetrwPreview(NetrwBrowseChgDir(1,NetrwGetWord(),1)) nnoremap P :call NetrwPrevWinOpen(1) - nnoremap qb :call NetrwBookmarkDir(2,b:netrw_curdir) - nnoremap mB :call NetrwBookmarkDir(6,b:netrw_curdir) + nnoremap qb :call NetrwBookHistHandler(2,b:netrw_curdir) + nnoremap mB :call NetrwBookHistHandler(6,b:netrw_curdir) nnoremap qf :call NetrwFileInfo(1,NetrwGetWord()) nnoremap r :let g:netrw_sort_direction= (g:netrw_sort_direction =~ 'n')? 'r' : 'n'exe "norm! 0"call NetrwRefresh(1,NetrwBrowseChgDir(1,'./')) nnoremap s :call NetrwSortStyle(1) nnoremap S :call NetSortSequence(1) nnoremap t :call NetrwSplit(4) - nnoremap u :call NetrwBookmarkDir(4,expand("%")) - nnoremap U :call NetrwBookmarkDir(5,expand("%")) + nnoremap u :call NetrwBookHistHandler(4,expand("%")) + nnoremap U :call NetrwBookHistHandler(5,expand("%")) nnoremap v :call NetrwSplit(5) nnoremap x :call netrw#NetrwBrowseX(NetrwBrowseChgDir(1,NetrwGetWord(),0),0)" nnoremap % :call NetrwOpenFile(1) @@ -1802,7 +1835,7 @@ fun! s:BrowserMaps(islocal) nnoremap :call NetrwRefresh(0,NetrwBrowseChgDir(0,'./')) nnoremap - :exe "norm! 0"call NetrwBrowse(0,NetrwBrowseChgDir(0,'../')) nnoremap a :call NetrwHide(0) - nnoremap mb :call NetrwBookmarkDir(0,b:netrw_curdir) + nnoremap mb :call NetrwBookHistHandler(0,b:netrw_curdir) nnoremap mc :call NetrwMarkFileCopy(0) nnoremap md :call NetrwMarkFileDiff(0) nnoremap me :call NetrwMarkFileEdit(0) @@ -1818,7 +1851,7 @@ fun! s:BrowserMaps(islocal) nnoremap mu :call NetrwUnMarkFile(0) nnoremap mx :call NetrwMarkFileExe(0) nnoremap mz :call NetrwMarkFileCompress(0) - nnoremap gb :call NetrwBookmarkDir(1,b:netrw_cur) + nnoremap gb :call NetrwBookHistHandler(1,b:netrw_cur) nnoremap gh :call NetrwHidden(0) nnoremap C :let g:netrw_chgwin= winnr() nnoremap i :call NetrwListStyle(0) @@ -1826,15 +1859,15 @@ fun! s:BrowserMaps(islocal) nnoremap O :call NetrwObtain(0) nnoremap p :call NetrwPreview(NetrwBrowseChgDir(1,NetrwGetWord(),1)) nnoremap P :call NetrwPrevWinOpen(0) - nnoremap qb :call NetrwBookmarkDir(2,b:netrw_curdir) - nnoremap mB :call NetrwBookmarkDir(6,b:netrw_curdir) + nnoremap qb :call NetrwBookHistHandler(2,b:netrw_curdir) + nnoremap mB :call NetrwBookHistHandler(6,b:netrw_curdir) nnoremap qf :call NetrwFileInfo(0,NetrwGetWord()) nnoremap r :let g:netrw_sort_direction= (g:netrw_sort_direction =~ 'n')? 'r' : 'n'exe "norm! 0"call NetrwBrowse(0,NetrwBrowseChgDir(0,'./')) nnoremap s :call NetrwSortStyle(0) nnoremap S :call NetSortSequence(0) nnoremap t :call NetrwSplit(1) - nnoremap u :call NetrwBookmarkDir(4,b:netrw_curdir) - nnoremap U :call NetrwBookmarkDir(5,b:netrw_curdir) + nnoremap u :call NetrwBookHistHandler(4,b:netrw_curdir) + nnoremap U :call NetrwBookHistHandler(5,b:netrw_curdir) nnoremap v :call NetrwSplit(2) nnoremap x :call netrw#NetrwBrowseX(NetrwBrowseChgDir(0,NetrwGetWord()),1) nnoremap % :call NetrwOpenFile(0) @@ -1884,7 +1917,7 @@ fun! s:ExplorePatHls(pattern) endfun " --------------------------------------------------------------------- -" s:NetrwBookmarkDir: {{{2 +" s:NetrwBookHistHandler: {{{2 " 0: (user: ) bookmark current directory " 1: (user: ) change to the bookmarked directory " 2: (user: ) list bookmarks @@ -1892,32 +1925,27 @@ endfun " 4: (user: ) go up (previous) bookmark " 5: (user: ) go down (next) bookmark " 6: (user: ) delete bookmark -fun! s:NetrwBookmarkDir(chg,curdir) -" call Dfunc("NetrwBookmarkDir(chg=".a:chg." curdir<".a:curdir.">) cnt=".v:count." bookmarkcnt=".g:NETRW_BOOKMARKMAX." histcnt=".g:NETRW_DIRHIST_CNT." bookmax=".g:NETRW_BOOKMARKMAX." histmax=".g:netrw_dirhistmax) +fun! s:NetrwBookHistHandler(chg,curdir) +" call Dfunc("NetrwBookHistHandler(chg=".a:chg." curdir<".a:curdir.">) cnt=".v:count." histcnt=".g:netrw_dirhist_cnt." histmax=".g:netrw_dirhistmax) if a:chg == 0 " bookmark the current directory " call Decho("(user: ) bookmark the current directory") - if v:count > 0 - " handle bookmark# specified via the count - let g:NETRW_BOOKMARKDIR_{v:count}= a:curdir - if !exists("g:NETRW_BOOKMARKMAX") - let g:NETRW_BOOKMARKMAX= v:count - elseif v:count > g:NETRW_BOOKMARKMAX - let g:NETRW_BOOKMARKMAX= v:count - endif - else - " handle no count specified - let g:NETRW_BOOKMARKMAX = g:NETRW_BOOKMARKMAX + 1 - let g:NETRW_BOOKMARKDIR_{g:NETRW_BOOKMARKMAX} = a:curdir + if !exists("g:netrw_bookmarklist") + let g:netrw_bookmarklist= [] + endif + if index(g:netrw_bookmarklist,a:curdir) == -1 + " curdir not currently in g:netrw_bookmarklist, so include it + call add(g:netrw_bookmarklist,a:curdir) + call sort(g:netrw_bookmarklist) endif echo "bookmarked the current directory" elseif a:chg == 1 " change to the bookmarked directory -" call Decho("(user: ) change to the bookmarked directory") - if exists("g:NETRW_BOOKMARKDIR_{v:count}") - exe "e ".fnameescape(g:NETRW_BOOKMARKDIR_{v:count}) +" call Decho("(user: <".v:count."mb>) change to the bookmarked directory") + if exists("g:netrw_bookmarklist[v:count-1]") + exe "e ".fnameescape(g:netrw_bookmarklist[v:count-1]) else echomsg "Sorry, bookmark#".v:count." doesn't exist!" endif @@ -1927,29 +1955,27 @@ fun! s:NetrwBookmarkDir(chg,curdir) let didwork= 0 " list user's bookmarks " call Decho("(user: ) list user's bookmarks") - if exists("g:NETRW_BOOKMARKMAX") -" call Decho("list bookmarks [0,".g:NETRW_BOOKMARKMAX."]") - let cnt= 0 - while cnt <= g:NETRW_BOOKMARKMAX - if exists("g:NETRW_BOOKMARKDIR_{cnt}") -" call Decho("Netrw Bookmark#".cnt.": ".g:NETRW_BOOKMARKDIR_{cnt}) - echo "Netrw Bookmark#".cnt.": ".g:NETRW_BOOKMARKDIR_{cnt} - let didwork= 1 - endif - let cnt= cnt + 1 - endwhile + if exists("g:netrw_bookmarklist") +" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks') + let cnt= 1 + for bmd in g:netrw_bookmarklist +" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1]) + echo "Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1] + let didwork = 1 + let cnt = cnt + 1 + endfor endif " list directory history - let cnt = g:NETRW_DIRHIST_CNT + let cnt = g:netrw_dirhist_cnt let first = 1 let histcnt = 0 - while ( first || cnt != g:NETRW_DIRHIST_CNT ) -" call Decho("first=".first." cnt=".cnt." dirhist_cnt=".g:NETRW_DIRHIST_CNT) + while ( first || cnt != g:netrw_dirhist_cnt ) +" call Decho("first=".first." cnt=".cnt." dirhist_cnt=".g:netrw_dirhist_cnt) let histcnt= histcnt + 1 - if exists("g:NETRW_DIRHIST_{cnt}") -" call Decho("Netrw History#".histcnt.": ".g:NETRW_DIRHIST_{cnt}) - echo "Netrw History#".histcnt.": ".g:NETRW_DIRHIST_{cnt} + if exists("g:netrw_dirhist_{cnt}") +" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt}) + echo "Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt} let didwork= 1 endif let first = 0 @@ -1965,22 +1991,21 @@ fun! s:NetrwBookmarkDir(chg,curdir) elseif a:chg == 3 " saves most recently visited directories (when they differ) " call Decho("(browsing) record curdir history") - if !exists("g:NETRW_DIRHIST_0") || g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT} != a:curdir - let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax -" let g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}= substitute(a:curdir,'[/\\]$','','e') - let g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}= a:curdir -" call Decho("save dirhist#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">") + if !exists("g:netrw_dirhist_cnt") || !exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}") || g:netrw_dirhist_{g:netrw_dirhist_cnt} != a:curdir + let g:netrw_dirhist_cnt = ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax + let g:netrw_dirhist_{g:netrw_dirhist_cnt} = a:curdir +" call Decho("save dirhist#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">") endif elseif a:chg == 4 " u: change to the previous directory stored on the history list " call Decho("(user: ) chg to prev dir from history") - let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT - 1 ) % g:netrw_dirhistmax - if g:NETRW_DIRHIST_CNT < 0 - let g:NETRW_DIRHIST_CNT= g:NETRW_DIRHIST_CNT + g:netrw_dirhistmax + let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - 1 ) % g:netrw_dirhistmax + if g:netrw_dirhist_cnt < 0 + let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax endif - if exists("g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}") -" call Decho("changedir u#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">") + if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}") +" call Decho("changedir u#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">") if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir") setlocal ma noro " call Decho("setlocal ma noro") @@ -1988,19 +2013,19 @@ fun! s:NetrwBookmarkDir(chg,curdir) setlocal nomod " call Decho("setlocal nomod") endif -" " call Decho("exe e! ".fnameescape(g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT})) - exe "e! ".fnameescape(g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}) +" " call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})) + exe "e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}) else - let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax + let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax echo "Sorry, no predecessor directory exists yet" endif elseif a:chg == 5 " U: change to the subsequent directory stored on the history list " call Decho("(user: ) chg to next dir from history") - let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax - if exists("g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}") -" call Decho("changedir U#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">") + let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax + if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}") +" call Decho("changedir U#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">") if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir") setlocal ma noro " call Decho("setlocal ma noro") @@ -2009,57 +2034,103 @@ fun! s:NetrwBookmarkDir(chg,curdir) setlocal nomod " call Decho("setlocal nomod") endif -" call Decho("exe e! ".fnameescape(g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT})) - exe "e! ".fnameescape(g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}) +" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})) + exe "e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}) else - let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT - 1 ) % g:netrw_dirhistmax - if g:NETRW_DIRHIST_CNT < 0 - let g:NETRW_DIRHIST_CNT= g:NETRW_DIRHIST_CNT + g:netrw_dirhistmax + let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - 1 ) % g:netrw_dirhistmax + if g:netrw_dirhist_cnt < 0 + let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax endif echo "Sorry, no successor directory exists yet" endif elseif a:chg == 6 - if v:count > 0 && v:count == g:NETRW_BOOKMARKMAX - " delete the v:count'th bookmark -" call Decho("delete bookmark#".v:count."<".g:NETRW_BOOKMARKDIR_{g:NETRW_BOOKMARKMAX}.">") - unlet g:NETRW_BOOKMARKDIR_{g:NETRW_BOOKMARKMAX} - let g:NETRW_BOOKMARKMAX= g:NETRW_BOOKMARKMAX - 1 - - elseif v:count > 0 -" call Decho("delete by shifting bookmark#".v:count."<".g:NETRW_BOOKMARKDIR_{v:count}.">") - let cnt= v:count - while cnt < g:NETRW_BOOKMARKMAX - let g:NETRW_BOOKMARKDIR_{cnt} = g:NETRW_BOOKMARKDIR_{(cnt+1)} - let cnt = cnt + 1 - endwhile - unlet g:NETRW_BOOKMARKDIR_{g:NETRW_BOOKMARKMAX} - let g:NETRW_BOOKMARKMAX= g:NETRW_BOOKMARKMAX - 1 - - elseif exists("b:netrw_curdir") - " look for current directory amongst the bookmarks and remove that bookmark -" call Decho("search for bookmark<".b:netrw_curdir.">") - let cnt= 1 - while cnt <= g:NETRW_BOOKMARKMAX -" call Decho("checking: g:NETRW_BOOKMARKDIR_".cnt."<".g:NETRW_BOOKMARKDIR_{cnt}.">") - if g:NETRW_BOOKMARKDIR_{cnt} == b:netrw_curdir - if cnt < g:NETRW_BOOKMARKMAX -" call Decho("delete bookmark#".cnt."<".b:netrw_curdir.">") - while cnt < g:NETRW_BOOKMARMAX - let g:NETRW_BOOKMARKDIR_{cnt} = g:NETRW_BOOKMARKDIR_{(cnt+1)} - let cnt = cnt + 1 - endwhile - endif - unlet g:NETRW_BOOKMARKDIR_{g:NETRW_BOOKMARKMAX} - let g:NETRW_BOOKMARKMAX= g:NETRW_BOOKMARKMAX - 1 - endif - let cnt= cnt + 1 - endwhile + " delete the v:count'th bookmark +" call Decho("delete bookmark#".v:count."<".g:netrw_bookmarklist[v:count-1].">") + let savefile= s:NetrwHome()."/.netrwbook" + if filereadable(savefile) + call s:NetrwBookHistSave() " done here to merge bookmarks first + call delete(savefile) endif - + call remove(g:netrw_bookmarklist,v:count-1) endif call s:NetrwBookmarkMenu() -" call Dret("NetrwBookmarkDir") +" call Dret("NetrwBookHistHandler") +endfun + +" --------------------------------------------------------------------- +" s:NetrwBookHistRead: this function reads bookmarks and history {{{2 +" Sister function: s:NetrwBookHistSave() +fun! s:NetrwBookHistRead() +" call Dfunc("s:NetrwBookHistRead()") + if !exists("s:netrw_initbookhist") + let savefile= s:NetrwHome()."/.netrwbook" + if filereadable(savefile) +" call Decho("sourcing .netrwbook") + exe "so ".savefile + endif + let savefile= s:NetrwHome()."/.netrwhist" + if filereadable(savefile) +" call Decho("sourcing .netrwhist") + exe "so ".savefile + endif + let s:netrw_initbookhist= 1 + au VimLeave * call s:NetrwBookHistSave() + endif +" call Dret("s:NetrwBookHistRead") +endfun + +" --------------------------------------------------------------------- +" s:NetrwBookHistSave: this function saves bookmarks and history {{{2 +" Sister function: s:NetrwBookHistRead() +" I used to do this via viminfo but that appears to +" be unreliable for long-term storage +" COMBAK: does $HOME work under windows??? +fun! s:NetrwBookHistSave() +" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax) + let savefile= s:NetrwHome()."/.netrwhist" + 1split + enew + setlocal noswf + + " save .netrwhist -- no attempt to merge + file .netrwhist + call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax) + call setline(2,"let g:netrw_dirhist_cnt =".g:netrw_dirhist_cnt) + let lastline = line("$") + let cnt = 1 + while cnt <= g:netrw_dirhist_cnt + call setline((cnt+lastline),'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'") + let cnt= cnt + 1 + endwhile + exe "silent! w! ".savefile + %d + + if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] + " merge and write .netrwbook + let savefile= s:NetrwHome()."/.netrwbook" + + if filereadable(savefile) + let booklist= deepcopy(g:netrw_bookmarklist) + exe "silent so ".savefile + for bdm in booklist + if index(g:netrw_bookmarklist,bdm) == -1 + call add(g:netrw_bookmarklist,bdm) + endif + endfor + call sort(g:netrw_bookmarklist) + exe "silent! w! ".savefile + endif + + " construct and save .netrwbook + call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist)) + exe "silent! w! ".savefile + endif + let bgone= bufnr("%") + q! + exe bgone."bwipe!" + +" call Dret("s:NetrwBookHistSave") endfun " --------------------------------------------------------------------- @@ -2072,6 +2143,9 @@ fun! s:NetrwBrowse(islocal,dirname) " call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%").">") " call Decho("tab#".tabpagenr()." win#".winnr()) " call Dredir("ls!") + if !exists("s:netrw_initbookhist") + call s:NetrwBookHistRead() + endif if exists("s:netrw_skipbrowse") unlet s:netrw_skipbrowse @@ -2269,6 +2343,14 @@ fun! s:NetrwBrowse(islocal,dirname) call s:BrowserMaps(a:islocal) call s:PerformListing(a:islocal) + " The s:LocalBrowseShellCmdRefresh() function is called by an autocmd + " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow, medium speed). + " However, s:NetrwBrowse() causes the ShellCmdPost event itself to fire once; setting + " the variable below avoids that second refresh of the screen. The s:LocalBrowseShellCmdRefresh() + " function gets called due to that autocmd; it notices that the following variable is set + " and skips the refresh and sets s:locbrowseshellcmd to zero. Oct 13, 2008 + let s:locbrowseshellcmd= 1 + " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap) " call Dret("s:NetrwBrowse : did PerformListing") return @@ -2328,7 +2410,7 @@ fun! s:NetrwGetBuffer(islocal,dirname) set ei=all exe "b ".w:netrw_treebufnr let &ei= eikeep -" call Dret("s:NetrwGetBuffer : bufnum#".bufnum."") +" call Dret("s:NetrwGetBuffer : bufnum#".w:netrw_treebufnr."") return endif let bufnum= -1 @@ -2706,37 +2788,47 @@ fun! s:NetrwBookmarkMenu() if !exists("s:netrw_menucnt") return endif -" call Dfunc("NetrwBookmarkMenu() bookmarkcnt=".g:NETRW_BOOKMARKMAX." histcnt=".g:NETRW_DIRHIST_CNT." menucnt=".s:netrw_menucnt) +" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhist_cnt." menucnt=".s:netrw_menucnt) " the following test assures that gvim is running, has menus available, and has menus enabled. if has("gui") && has("menu") && has("gui_running") && &go =~ 'm' && g:netrw_menu if exists("g:NetrwTopLvlMenu") " call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)") exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Bookmarks' + exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete' + endif + if !exists("s:netrw_initbookhist") + call s:NetrwBookHistRead() endif " show bookmarked places - let cnt = 1 - while cnt <= g:NETRW_BOOKMARKMAX - if exists("g:NETRW_BOOKMARKDIR_{cnt}") - let bmdir= escape(g:NETRW_BOOKMARKDIR_{cnt},'. ') -" call Decho('silent! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmdir.' :e '.bmdir) - exe 'silent! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmdir.' :e '.bmdir."\" - endif - let cnt= cnt + 1 - endwhile + if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] + let cnt= 1 + for bmd in g:netrw_bookmarklist +" call Decho('silent! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd) + let bmd= escape(bmd,'. ') + + " show bookmarks for goto menu + exe 'silent! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\" + + " show bookmarks for deletion menu + exe 'silent! menu '.g:NetrwMenuPriority.".8.2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete.'.bmd.' '.cnt."mB" + let cnt= cnt + 1 + endfor + + endif " show directory browsing history - let cnt = g:NETRW_DIRHIST_CNT + let cnt = g:netrw_dirhist_cnt let first = 1 let histcnt = 0 - while ( first || cnt != g:NETRW_DIRHIST_CNT ) + while ( first || cnt != g:netrw_dirhist_cnt ) let histcnt = histcnt + 1 - let priority = g:NETRW_DIRHIST_CNT + histcnt - if exists("g:NETRW_DIRHIST_{cnt}") - let bmdir= escape(g:NETRW_DIRHIST_{cnt},'/&? ') -" call Decho('silent! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.bmdir.' :e '.bmdir) - exe 'silent! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.bmdir.' :e '.bmdir."\" + let priority = g:netrw_dirhist_cnt + histcnt + if exists("g:netrw_dirhist_{cnt}") + let histdir= escape(g:netrw_dirhist_{cnt},'./&? ') +" call Decho('silent! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir) + exe 'silent! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\" endif let first = 0 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax @@ -2744,6 +2836,7 @@ fun! s:NetrwBookmarkMenu() let cnt= cnt + g:netrw_dirhistmax endif endwhile + endif " call Dret("NetrwBookmarkMenu") endfun @@ -2991,6 +3084,7 @@ fun! netrw#NetrwBrowseX(fname,remote) if has("win32") || has("win95") || has("win64") || has("win16") let exten= substitute(exten,'^.*$','\L&\E','') endif +" call Decho("exten<".exten.">") " seems kde systems often have gnome-open due to dependencies, even though " gnome-open's subsidiary display tools are largely absent. Kde systems @@ -3009,16 +3103,25 @@ fun! netrw#NetrwBrowseX(fname,remote) if a:remote == 1 " create a local copy - let fname= fnamemodify(tempname(),":r").".".exten -" call Decho("a:remote=".a:remote.": create a local copy of <".fname."> as <".fname.">") - exe "silent keepjumps bot 1new ".fnameescape(fname) +" call Decho("a:remote=".a:remote.": create a local copy of <".a:fname.">") setlocal bh=delete -" call Decho("read <".fnameescape(fname).">, now writing: exe w! ".fnameescape(fname)) - exe "silent! w! ".fnameescape(fname) - q + call netrw#NetRead(3,a:fname) + " attempt to rename tempfile + let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','') + let newname= substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','') +" call Decho("basename<".basename.">") +" call Decho("newname <".newname.">") + if rename(s:netrw_tmpfile,newname) == 0 + " renaming succeeded + let fname= newname + else + " renaming failed + let fname= s:netrw_tmpfile + endif else let fname= a:fname endif +" call Decho("fname<".fname.">") " call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten)) " set up redirection @@ -3125,10 +3228,22 @@ endfun " --------------------------------------------------------------------- " netrw#Explore: launch the local browser in the directory of the current file {{{2 -" dosplit==0: the window will be split iff the current file has -" been modified -" dosplit==1: the window will be split before running the local -" browser +" indx: == -1: Nexplore +" == -2: Pexplore +" == +: this is overloaded: +" * If Nexplore/Pexplore is in use, then this refers to the +" indx'th item in the w:netrw_explore_list[] of items which +" matched the */pattern **/pattern *//pattern **//pattern +" * If Hexplore or Vexplore, then this will override +" g:netrw_winsize to specify the qty of rows or columns the +" newly split window should have. +" dosplit==0: the window will be split iff the current file has been modified +" dosplit==1: the window will be split before running the local browser +" style == 0: Explore style == 1: Explore! +" == 2: Hexplore style == 3: Hexplore! +" == 4: Vexplore style == 5: Vexplore! +" == 6: Texplore +"DechoTabOn fun! netrw#Explore(indx,dosplit,style,...) " call Dfunc("netrw#Explore(indx=".a:indx." dosplit=".a:dosplit." style=".a:style.",a:1<".a:1.">) &modified=".&modified." a:0=".a:0) if !exists("b:netrw_curdir") @@ -3147,30 +3262,34 @@ fun! netrw#Explore(indx,dosplit,style,...) if a:dosplit || &modified || a:style == 6 " call Decho("case: dosplit=".a:dosplit." modified=".&modified." a:style=".a:style) call s:SaveWinVars() + let winsize= g:netrw_winsize + if a:indx > 0 + let winsize= a:indx + endif if a:style == 0 " Explore, Sexplore " call Decho("style=0: Explore or Sexplore") - exe g:netrw_winsize."wincmd s" + exe winsize."wincmd s" elseif a:style == 1 "Explore!, Sexplore! " call Decho("style=1: Explore! or Sexplore!") - exe g:netrw_winsize."wincmd v" + exe winsize."wincmd v" elseif a:style == 2 " Hexplore " call Decho("style=2: Hexplore") - exe "bel ".g:netrw_winsize."wincmd s" + exe "bel ".winsize."wincmd s" elseif a:style == 3 " Hexplore! " call Decho("style=3: Hexplore!") - exe "abo ".g:netrw_winsize."wincmd s" + exe "abo ".winsize."wincmd s" elseif a:style == 4 " Vexplore " call Decho("style=4: Vexplore") - exe "lefta ".g:netrw_winsize."wincmd v" + exe "lefta ".winsize."wincmd v" elseif a:style == 5 " Vexplore! " call Decho("style=5: Vexplore!") - exe "rightb ".g:netrw_winsize."wincmd v" + exe "rightb ".winsize."wincmd v" elseif a:style == 6 " Texplore call s:SaveBufVars() @@ -3301,9 +3420,10 @@ fun! netrw#Explore(indx,dosplit,style,...) if !exists("w:netrw_explore_indx") let w:netrw_explore_indx= 0 endif + let indx = a:indx " call Decho("starpat=".starpat.": set indx= [a:indx=".indx."]") -" + if indx == -1 " Nexplore " call Decho("case Nexplore with starpat=".starpat.": (indx=".indx.")") @@ -3364,6 +3484,7 @@ fun! netrw#Explore(indx,dosplit,style,...) if starpat == 1 " starpat=1: Explore *//pattern (current directory only search for files containing pattern) " call Decho("starpat=".starpat.": build *//pattern list") +" call Decho("pattern<".pattern.">") exe "vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*" let w:netrw_explore_list = map(getqflist(),'bufname(v:val.bufnr)') if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif @@ -3389,14 +3510,12 @@ fun! netrw#Explore(indx,dosplit,style,...) elseif starpat == 3 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat) " call Decho("starpat=".starpat.": build */filepat list") - let dirname = substitute(dirname,'^\*/','','') - if dirname !~ '\$*?[' && (!filereadable(dirname) || !filewritable(dirname)) -" call Dret("netrw#Explore : no files matched pattern") - call netrw#ErrorMsg(s:NOTE,"no files matched Explore pattern",72) - return - endif - let w:netrw_explore_list= split(expand(b:netrw_curdir."/".dirname),'\n') - if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif + let filepat= substitute(dirname,'^\*/','','') + let filepat= substitute(filepat,'^[%#<]','\\&','') +" call Decho("b:netrw_curdir<".b:netrw_curdir.">") +" call Decho("filepat<".filepat.">") + let w:netrw_explore_list= split(expand(b:netrw_curdir."/".filepat),'\n') + if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif elseif starpat == 4 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat) @@ -3491,17 +3610,18 @@ fun! netrw#Explore(indx,dosplit,style,...) let prvfname= "" for fname in w:netrw_explore_list " call Decho("fname<".fname.">") +"COMBAK -- g:netrw_markfileesc."'".g:netrw_markfileesc."'" ??? if fname =~ '^'.b:netrw_curdir if s:explore_match == "" - let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc."'".g:netrw_markfileesc."'").'\>' + let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>' else - let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc."'".g:netrw_markfileesc."'").'\>' + let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>' endif elseif fname !~ '^/' && fname != prvfname if s:explore_match == "" - let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc."'".g:netrw_markfileesc."'").'\>' + let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>' else - let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc."'".g:netrw_markfileesc."'").'\>' + let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>' endif endif let prvfname= fname @@ -3600,6 +3720,48 @@ fun! s:NetrwHidden(islocal) " call Dret("s:NetrwHidden") endfun +" --------------------------------------------------------------------- +" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2 +fun! s:NetrwHome() +" call Dfunc("s:NetrwHome()") + if exists("g:netrw_home") + let home= g:netrw_home + else + " go to vim plugin home + for home in split(&rtp,',') + [''] + if isdirectory(home) && filewritable(home) | break | endif + let basehome= substitute(home,'[/\\]\.vim$','','') + if isdirectory(basehome) && filewritable(basehome) + let home= basehome."/.vim" + break + endif + endfor + if home == "" + " just pick the first directory +" call Decho("just pick first directory in &rtp") + let home= substitute(&rtp,',.*$','','') + endif + if (has("win32") || has("win95") || has("win64") || has("win16")) + let home= substitute(home,'/','\\','g') + endif + endif + " insure that the home directory exists +" call Decho("picked home<".home.">") + if !isdirectory(home) + if exists("g:netrw_mkdir") +" call Decho("home<".home."> isn't a directory -- making it now with g:netrw_mkdir<".g:netrw_mkdir.">") +" call Decho("system(".g:netrw_mkdir." ".s:Escape(home).")") + call system(g:netrw_mkdir." ".s:Escape(home)) + else +" call Decho("home<".home."> isn't a directory -- making it now with mkdir()") + call mkdir(home) + endif + endif + let g:netrw_home= home +" call Dret("s:NetrwHome <".home.">") + return home +endfun + " --------------------------------------------------------------------- " s:NetrwLeftmouse: handles the when in a netrw browsing window {{{2 fun! s:NetrwLeftmouse(islocal) @@ -4048,7 +4210,9 @@ fun! s:NetrwMarkFileCopy(islocal) if a:islocal call s:NetrwRefreshDir(a:islocal,b:netrw_curdir) endif - call s:LocalBrowseShellCmdRefresh() + if g:netrw_fastbrowse <= 1 + call s:LocalBrowseShellCmdRefresh() + endif " call Dret("s:NetrwMarkFileCopy 1") return 1 @@ -4356,7 +4520,9 @@ fun! s:NetrwMarkFileMove(islocal) if a:islocal call s:NetrwRefreshDir(a:islocal,b:netrw_curdir) endif - call s:LocalBrowseShellCmdRefresh() + if g:netrw_fastbrowse <= 1 + call s:LocalBrowseShellCmdRefresh() + endif " call Dret("s:NetrwMarkFileMove") endfun @@ -4584,7 +4750,7 @@ fun! s:NetrwMarkFileTgt(islocal) endif let s:netrwmftgt_islocal= a:islocal - if g:netrw_fastbrowse > 0 + if g:netrw_fastbrowse <= 1 call s:LocalBrowseShellCmdRefresh() endif call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) @@ -4719,20 +4885,17 @@ fun! s:NetrwMenu(domenu) " call Decho("initialize menu") let s:netrw_menu_enabled= 1 exe 'silent! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help ' - call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4 exe 'silent! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :' exe 'silent! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory- -' exe 'silent! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewerx x' exe 'silent! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directorymb mb' - exe 'silent! menu '.g:NetrwMenuPriority.'.8.2 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ DeletemB mB' - exe 'silent! menu '.g:NetrwMenuPriority.'.8.3 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Bookmarkgb gb' exe 'silent! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)u u' exe 'silent! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)U U' exe 'silent! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Listqb qb' - exe 'silent! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List'." \NetrwHideEdit" + exe 'silent! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List'." \'" exe 'silent! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ SequenceS S' exe 'silent! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files'."gh gh" - exe 'silent! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing'." \NetrwRefresh" + exe 'silent! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing'." \" exe 'silent! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options:NetrwSettings '.":NetrwSettings\" exe 'silent! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/DirectoryD D' exe 'silent! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window '."\" @@ -4770,6 +4933,7 @@ fun! s:NetrwMenu(domenu) exe 'silent! menu '.g:NetrwMenuPriority.'.16.4 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method\ (name-time-size)s s' exe 'silent! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/DirectoryR R' exe 'silent! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directoryc c' + call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x let s:netrw_menucnt= 28 elseif !a:domenu @@ -5482,12 +5646,12 @@ fun! s:NetrwSplit(mode) elseif a:mode == 1 " remote and t - let cursorword = s:NetrwGetWord() + let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord()) " call Decho("tabnew") tabnew let s:didsplit= 1 call s:RestoreWinVars() - call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,cursorword)) + call s:NetrwBrowse(0,newdir) unlet s:didsplit elseif a:mode == 2 @@ -5810,7 +5974,7 @@ fun! s:PerformListing(islocal) endif " save current directory on directory history list - call s:NetrwBookmarkDir(3,b:netrw_curdir) + call s:NetrwBookHistHandler(3,b:netrw_curdir) " Set up the banner {{{3 " call Decho("set up banner") @@ -6739,6 +6903,14 @@ fun! s:LocalBrowseShellCmdRefresh() " call Dret("LocalBrowseShellCmdRefresh : don't refresh when focus not on netrw windwo") return endif + if exists("s:locbrowseshellcmd") + if s:locbrowseshellcmd + let s:locbrowseshellcmd= 0 +" call Dret("LocalBrowseShellCmdRefresh : NetrwBrowse itself caused the refresh") + return + endif + let s:locbrowseshellcmd= 0 + endif let itab = 1 let buftablist = [] while itab <= tabpagenr("$") @@ -7030,9 +7202,11 @@ fun! s:LocalFastBrowser() augroup AuNetrwShellCmd au! if (has("win32") || has("win95") || has("win64") || has("win16")) +" call Decho("autocmd: ShellCmdPost * call s:LocalBrowseShellCmdRefresh()") au ShellCmdPost * call s:LocalBrowseShellCmdRefresh() else au ShellCmdPost,FocusGained * call s:LocalBrowseShellCmdRefresh() +" call Decho("autocmd: ShellCmdPost,FocusGained * call s:LocalBrowseShellCmdRefresh()") endif augroup END endif @@ -7059,7 +7233,7 @@ endfun " 0=note = s:NOTE " 1=warning = s:WARNING " 2=error = s:ERROR -" Aug 22, 2008 : max errnum currently is 72 +" Oct 12, 2008 : max errnum currently is 73 fun! netrw#ErrorMsg(level,msg,errnum) " call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow) @@ -7287,7 +7461,7 @@ fun! s:GetTempfile(fname) endif " let netrw#NetSource() know about the tmpfile - let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() + let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#NetrwBrowseX() " call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">") " o/s dependencies @@ -7659,8 +7833,7 @@ fun! s:SetRexDir(islocal,dirname) if a:islocal exe 'com! Rexplore call s:NetrwRexplore(1,"'.escape(a:dirname,'"\').'")' if g:netrw_retmap - silent! unmap <2-leftmouse> - if !hasmapto("NetrwReturn") + if !hasmapto("NetrwReturn") && maparg("<2-leftmouse>","n") == "" nmap <2-leftmouse> NetrwReturn endif let dir = escape(a:dirname, s:netrw_map_escape) @@ -7669,8 +7842,7 @@ fun! s:SetRexDir(islocal,dirname) else exe 'com! Rexplore call s:NetrwRexplore(0,"'.escape(a:dirname,'"\').'")' if g:netrw_retmap - silent! unmap <2-leftmouse> - if !hasmapto("NetrwReturn") + if !hasmapto("NetrwReturn") && maparg("<2-leftmouse>","n") == "" nmap <2-leftmouse> NetrwReturn endif let dir = escape(a:dirname, s:netrw_map_escape) diff --git a/vimfiles/autoload/netrwFileHandlers.vim b/vimfiles/autoload/netrwFileHandlers.vim index 97c4837..1515b00 100644 --- a/vimfiles/autoload/netrwFileHandlers.vim +++ b/vimfiles/autoload/netrwFileHandlers.vim @@ -1,355 +1,361 @@ -" netrwFileHandlers: contains various extension-based file handlers for -" netrw's browsers' x command ("eXecute launcher") -" Author: Charles E. Campbell, Jr. -" Date: May 30, 2006 -" Version: 9 -" Copyright: Copyright (C) 1999-2005 Charles E. Campbell, Jr. {{{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, -" netrwFileHandlers.vim is provided *as is* and comes with no -" warranty of any kind, either expressed or implied. In no -" event will the copyright holder be liable for any damages -" resulting from the use of this software. -" -" Rom 6:23 (WEB) For the wages of sin is death, but the free gift of God {{{1 -" is eternal life in Christ Jesus our Lord. - -" --------------------------------------------------------------------- -" Load Once: {{{1 -if exists("g:loaded_netrwFileHandlers") || &cp - finish -endif -let s:keepcpo= &cpo -set cpo&vim -let g:loaded_netrwFileHandlers= "v9" - -" --------------------------------------------------------------------- -" netrwFileHandlers#Invoke: {{{1 -fun! netrwFileHandlers#Invoke(exten,fname) -" call Dfunc("netrwFileHandlers#Invoke(exten<".a:exten."> fname<".a:fname.">)") - let fname= a:fname - " list of supported special characters. Consider rcs,v --- that can be - " supported with a NFH_rcsCOMMAv() handler - if a:fname =~ '[@:,$!=\-+%?;~]' - let specials= { -\ '@' : 'AT', -\ ':' : 'COLON', -\ ',' : 'COMMA', -\ '$' : 'DOLLAR', -\ '!' : 'EXCLAMATION', -\ '=' : 'EQUAL', -\ '-' : 'MINUS', -\ '+' : 'PLUS', -\ '%' : 'PERCENT', -\ '?' : 'QUESTION', -\ ';' : 'SEMICOLON', -\ '~' : 'TILDE'} - let fname= substitute(a:fname,'[@:,$!=\-+%?;~]','\=specials[submatch(0)]','ge') -" call Decho('fname<'.fname.'> done with dictionary') - endif - - if a:exten != "" && exists("*NFH_".a:exten) - " support user NFH_*() functions -" call Decho("let ret= netrwFileHandlers#NFH_".a:exten.'("'.fname.'")') - exe "let ret= NFH_".a:exten.'("'.fname.'")' - elseif a:exten != "" && exists("*s:NFH_".a:exten) - " use builtin-NFH_*() functions -" call Decho("let ret= netrwFileHandlers#NFH_".a:exten.'("'.fname.'")') - exe "let ret= s:NFH_".a:exten.'("'.fname.'")' - endif - -" call Dret("netrwFileHandlers#Invoke 0 : ret=".ret) - return 0 -endfun - -" --------------------------------------------------------------------- -" s:NFH_html: handles html when the user hits "x" when the {{{1 -" cursor is atop a *.html file -fun! s:NFH_html(pagefile) -" call Dfunc("s:NFH_html(".a:pagefile.")") - - let page= substitute(a:pagefile,'^','file://','') - - if executable("mozilla") -" call Decho("executing !mozilla ".page) - exe "!mozilla ".g:netrw_shq.page.g:netrw_shq - elseif executable("netscape") -" call Decho("executing !netscape ".page) - exe "!netscape ".g:netrw_shq..page.g:netrw_shq - else -" call Dret("s:NFH_html 0") - return 0 - endif - -" call Dret("s:NFH_html 1") - return 1 -endfun - -" --------------------------------------------------------------------- -" s:NFH_htm: handles html when the user hits "x" when the {{{1 -" cursor is atop a *.htm file -fun! s:NFH_htm(pagefile) -" call Dfunc("s:NFH_htm(".a:pagefile.")") - - let page= substitute(a:pagefile,'^','file://','') - - if executable("mozilla") -" call Decho("executing !mozilla ".page) - exe "!mozilla ".g:netrw_shq.page.g:netrw_shq - elseif executable("netscape") -" call Decho("executing !netscape ".page) - exe "!netscape ".g:netrw_shq.page.g:netrw_shq - else -" call Dret("s:NFH_htm 0") - return 0 - endif - -" call Dret("s:NFH_htm 1") - return 1 -endfun - -" --------------------------------------------------------------------- -" s:NFH_jpg: {{{1 -fun! s:NFH_jpg(jpgfile) -" call Dfunc("s:NFH_jpg(jpgfile<".a:jpgfile.">)") - - if executable("gimp") - exe "silent! !gimp -s ".g:netrw_shq.a:jpgfile.g:netrw_shq - elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE") -" call Decho("silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".escape(a:jpgfile," []|'")) - exe "!".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".g:netrw_shq.a:jpgfile.g:netrw_shq - else -" call Dret("s:NFH_jpg 0") - return 0 - endif - -" call Dret("s:NFH_jpg 1") - return 1 -endfun - -" --------------------------------------------------------------------- -" s:NFH_gif: {{{1 -fun! s:NFH_gif(giffile) -" call Dfunc("s:NFH_gif(giffile<".a:giffile.">)") - - if executable("gimp") - exe "silent! !gimp -s ".g:netrw_shq.a:giffile.g:netrw_shq - elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE") - exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".g:netrw_shq.a:giffile.g:netrw_shq - else -" call Dret("s:NFH_gif 0") - return 0 - endif - -" call Dret("s:NFH_gif 1") - return 1 -endfun - -" --------------------------------------------------------------------- -" s:NFH_png: {{{1 -fun! s:NFH_png(pngfile) -" call Dfunc("s:NFH_png(pngfile<".a:pngfile.">)") - - if executable("gimp") - exe "silent! !gimp -s ".g:netrw_shq.a:pngfile.g:netrw_shq - elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE") - exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".g:netrw_shq.a:pngfile.g:netrw_shq - else -" call Dret("s:NFH_png 0") - return 0 - endif - -" call Dret("s:NFH_png 1") - return 1 -endfun - -" --------------------------------------------------------------------- -" s:NFH_pnm: {{{1 -fun! s:NFH_pnm(pnmfile) -" call Dfunc("s:NFH_pnm(pnmfile<".a:pnmfile.">)") - - if executable("gimp") - exe "silent! !gimp -s ".g:netrw_shq.a:pnmfile.g:netrw_shq - elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE") - exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".g:netrw_shq.a:pnmfile.g:netrw_shq - else -" call Dret("s:NFH_pnm 0") - return 0 - endif - -" call Dret("s:NFH_pnm 1") - return 1 -endfun - -" --------------------------------------------------------------------- -" s:NFH_bmp: visualize bmp files {{{1 -fun! s:NFH_bmp(bmpfile) -" call Dfunc("s:NFH_bmp(bmpfile<".a:bmpfile.">)") - - if executable("gimp") - exe "silent! !gimp -s ".a:bmpfile - elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE") - exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".g:netrw_shq.a:bmpfile.g:netrw_shq - else -" call Dret("s:NFH_bmp 0") - return 0 - endif - -" call Dret("s:NFH_bmp 1") - return 1 -endfun - -" --------------------------------------------------------------------- -" s:NFH_pdf: visualize pdf files {{{1 -fun! s:NFH_pdf(pdf) -" call Dfunc("s:NFH_pdf(pdf<".a:pdf.">)") - if executable("gs") - exe 'silent! !gs '.g:netrw_shq.a:pdf.g:netrw_shq - elseif executable("pdftotext") - exe 'silent! pdftotext -nopgbrk '.g:netrw_shq.a:pdf.g:netrw_shq - else -" call Dret("s:NFH_pdf 0") - return 0 - endif - -" call Dret("s:NFH_pdf 1") - return 1 -endfun - -" --------------------------------------------------------------------- -" s:NFH_doc: visualize doc files {{{1 -fun! s:NFH_doc(doc) -" call Dfunc("s:NFH_doc(doc<".a:doc.">)") - - if executable("oowriter") - exe 'silent! !oowriter '.g:netrw_shq.a:doc.g:netrw_shq - redraw! - else -" call Dret("s:NFH_doc 0") - return 0 - endif - -" call Dret("s:NFH_doc 1") - return 1 -endfun - -" --------------------------------------------------------------------- -" s:NFH_sxw: visualize sxw files {{{1 -fun! s:NFH_sxw(sxw) -" call Dfunc("s:NFH_sxw(sxw<".a:sxw.">)") - - if executable("oowriter") - exe 'silent! !oowriter '.g:netrw_shq.a:sxw.g:netrw_shq - redraw! - else -" call Dret("s:NFH_sxw 0") - return 0 - endif - -" call Dret("s:NFH_sxw 1") - return 1 -endfun - -" --------------------------------------------------------------------- -" s:NFH_xls: visualize xls files {{{1 -fun! s:NFH_xls(xls) -" call Dfunc("s:NFH_xls(xls<".a:xls.">)") - - if executable("oocalc") - exe 'silent! !oocalc '.g:netrw_shq.a:xls.g:netrw_shq - redraw! - else -" call Dret("s:NFH_xls 0") - return 0 - endif - -" call Dret("s:NFH_xls 1") - return 1 -endfun - -" --------------------------------------------------------------------- -" s:NFH_ps: handles PostScript files {{{1 -fun! s:NFH_ps(ps) -" call Dfunc("s:NFH_ps(ps<".a:ps.">)") - if executable("gs") -" call Decho("exe silent! !gs ".a:ps) - exe "silent! !gs ".g:netrw_shq.a:ps.g:netrw_shq - redraw! - elseif executable("ghostscript") -" call Decho("exe silent! !ghostscript ".a:ps) - exe "silent! !ghostscript ".g:netrw_shq.a:ps.g:netrw_shq - redraw! - elseif executable("gswin32") -" call Decho("exe silent! !gswin32 ".g:netrw_shq.a:ps.g:netrw_shq) - exe "silent! !gswin32 ".g:netrw_shq.a:ps.g:netrw_shq - redraw! - else -" call Dret("s:NFH_ps 0") - return 0 - endif - -" call Dret("s:NFH_ps 1") - return 1 -endfun - -" --------------------------------------------------------------------- -" s:NFH_eps: handles encapsulated PostScript files {{{1 -fun! s:NFH_eps(eps) -" call Dfunc("s:NFH_eps()") - if executable("gs") - exe "silent! !gs ".g:netrw_shq.a:eps.g:netrw_shq - redraw! - elseif executable("ghostscript") - exe "silent! !ghostscript ".g:netrw_shq.a:eps.g:netrw_shq - redraw! - elseif executable("ghostscript") - exe "silent! !ghostscript ".g:netrw_shq.a:eps.g:netrw_shq - redraw! - elseif executable("gswin32") - exe "silent! !gswin32 ".g:netrw_shq.a:eps.g:netrw_shq - redraw! - else -" call Dret("s:NFH_eps 0") - return 0 - endif -" call Dret("s:NFH_eps 0") - return 1 -endfun - -" --------------------------------------------------------------------- -" s:NFH_fig: handles xfig files {{{1 -fun! s:NFH_fig(fig) -" call Dfunc("s:NFH_fig()") - if executable("xfig") - exe "silent! !xfig ".a:fig - redraw! - else -" call Dret("s:NFH_fig 0") - return 0 - endif - -" call Dret("s:NFH_fig 1") - return 1 -endfun - -" --------------------------------------------------------------------- -" s:NFH_obj: handles tgif's obj files {{{1 -fun! s:NFH_obj(obj) -" call Dfunc("s:NFH_obj()") - if has("unix") && executable("tgif") - exe "silent! !tgif ".a:obj - redraw! - else -" call Dret("s:NFH_obj 0") - return 0 - endif - -" call Dret("s:NFH_obj 1") - return 1 -endfun - -let &cpo= s:keepcpo -" --------------------------------------------------------------------- -" Modelines: {{{1 -" vim: fdm=marker +" netrwFileHandlers: contains various extension-based file handlers for +" netrw's browsers' x command ("eXecute launcher") +" Author: Charles E. Campbell, Jr. +" Date: Sep 30, 2008 +" Version: 10 +" Copyright: Copyright (C) 1999-2008 Charles E. Campbell, Jr. {{{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, +" netrwFileHandlers.vim is provided *as is* and comes with no +" warranty of any kind, either expressed or implied. In no +" event will the copyright holder be liable for any damages +" resulting from the use of this software. +" +" Rom 6:23 (WEB) For the wages of sin is death, but the free gift of God {{{1 +" is eternal life in Christ Jesus our Lord. + +" --------------------------------------------------------------------- +" Load Once: {{{1 +if exists("g:loaded_netrwFileHandlers") || &cp + finish +endif +let g:loaded_netrwFileHandlers= "v10" +if v:version < 702 + echohl WarningMsg + echo "***warning*** this version of netrwFileHandlers needs vim 7.2" + echohl Normal + finish +endif +let s:keepcpo= &cpo +set cpo&vim + +" --------------------------------------------------------------------- +" netrwFileHandlers#Invoke: {{{1 +fun! netrwFileHandlers#Invoke(exten,fname) +" call Dfunc("netrwFileHandlers#Invoke(exten<".a:exten."> fname<".a:fname.">)") + let fname= a:fname + " list of supported special characters. Consider rcs,v --- that can be + " supported with a NFH_rcsCOMMAv() handler + if a:fname =~ '[@:,$!=\-+%?;~]' + let specials= { +\ '@' : 'AT', +\ ':' : 'COLON', +\ ',' : 'COMMA', +\ '$' : 'DOLLAR', +\ '!' : 'EXCLAMATION', +\ '=' : 'EQUAL', +\ '-' : 'MINUS', +\ '+' : 'PLUS', +\ '%' : 'PERCENT', +\ '?' : 'QUESTION', +\ ';' : 'SEMICOLON', +\ '~' : 'TILDE'} + let fname= substitute(a:fname,'[@:,$!=\-+%?;~]','\=specials[submatch(0)]','ge') +" call Decho('fname<'.fname.'> done with dictionary') + endif + + if a:exten != "" && exists("*NFH_".a:exten) + " support user NFH_*() functions +" call Decho("let ret= netrwFileHandlers#NFH_".a:exten.'("'.fname.'")') + exe "let ret= NFH_".a:exten.'("'.fname.'")' + elseif a:exten != "" && exists("*s:NFH_".a:exten) + " use builtin-NFH_*() functions +" call Decho("let ret= netrwFileHandlers#NFH_".a:exten.'("'.fname.'")') + exe "let ret= s:NFH_".a:exten.'("'.fname.'")' + endif + +" call Dret("netrwFileHandlers#Invoke 0 : ret=".ret) + return 0 +endfun + +" --------------------------------------------------------------------- +" s:NFH_html: handles html when the user hits "x" when the {{{1 +" cursor is atop a *.html file +fun! s:NFH_html(pagefile) +" call Dfunc("s:NFH_html(".a:pagefile.")") + + let page= substitute(a:pagefile,'^','file://','') + + if executable("mozilla") +" call Decho("executing !mozilla ".page) + exe "!mozilla ".shellescape(page,1) + elseif executable("netscape") +" call Decho("executing !netscape ".page) + exe "!netscape ".shellescape(page,1) + else +" call Dret("s:NFH_html 0") + return 0 + endif + +" call Dret("s:NFH_html 1") + return 1 +endfun + +" --------------------------------------------------------------------- +" s:NFH_htm: handles html when the user hits "x" when the {{{1 +" cursor is atop a *.htm file +fun! s:NFH_htm(pagefile) +" call Dfunc("s:NFH_htm(".a:pagefile.")") + + let page= substitute(a:pagefile,'^','file://','') + + if executable("mozilla") +" call Decho("executing !mozilla ".page) + exe "!mozilla ".shellescape(page,1) + elseif executable("netscape") +" call Decho("executing !netscape ".page) + exe "!netscape ".shellescape(page,1) + else +" call Dret("s:NFH_htm 0") + return 0 + endif + +" call Dret("s:NFH_htm 1") + return 1 +endfun + +" --------------------------------------------------------------------- +" s:NFH_jpg: {{{1 +fun! s:NFH_jpg(jpgfile) +" call Dfunc("s:NFH_jpg(jpgfile<".a:jpgfile.">)") + + if executable("gimp") + exe "silent! !gimp -s ".shellescape(a:jpgfile,1) + elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE") +" call Decho("silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".escape(a:jpgfile," []|'")) + exe "!".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".shellescape(a:jpgfile,1) + else +" call Dret("s:NFH_jpg 0") + return 0 + endif + +" call Dret("s:NFH_jpg 1") + return 1 +endfun + +" --------------------------------------------------------------------- +" s:NFH_gif: {{{1 +fun! s:NFH_gif(giffile) +" call Dfunc("s:NFH_gif(giffile<".a:giffile.">)") + + if executable("gimp") + exe "silent! !gimp -s ".shellescape(a:giffile,1) + elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE") + exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".shellescape(a:giffile,1) + else +" call Dret("s:NFH_gif 0") + return 0 + endif + +" call Dret("s:NFH_gif 1") + return 1 +endfun + +" --------------------------------------------------------------------- +" s:NFH_png: {{{1 +fun! s:NFH_png(pngfile) +" call Dfunc("s:NFH_png(pngfile<".a:pngfile.">)") + + if executable("gimp") + exe "silent! !gimp -s ".shellescape(a:pngfile,1) + elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE") + exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".shellescape(a:pngfile,1) + else +" call Dret("s:NFH_png 0") + return 0 + endif + +" call Dret("s:NFH_png 1") + return 1 +endfun + +" --------------------------------------------------------------------- +" s:NFH_pnm: {{{1 +fun! s:NFH_pnm(pnmfile) +" call Dfunc("s:NFH_pnm(pnmfile<".a:pnmfile.">)") + + if executable("gimp") + exe "silent! !gimp -s ".shellescape(a:pnmfile,1) + elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE") + exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".shellescape(a:pnmfile,1) + else +" call Dret("s:NFH_pnm 0") + return 0 + endif + +" call Dret("s:NFH_pnm 1") + return 1 +endfun + +" --------------------------------------------------------------------- +" s:NFH_bmp: visualize bmp files {{{1 +fun! s:NFH_bmp(bmpfile) +" call Dfunc("s:NFH_bmp(bmpfile<".a:bmpfile.">)") + + if executable("gimp") + exe "silent! !gimp -s ".a:bmpfile + elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE") + exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".shellescape(a:bmpfile,1) + else +" call Dret("s:NFH_bmp 0") + return 0 + endif + +" call Dret("s:NFH_bmp 1") + return 1 +endfun + +" --------------------------------------------------------------------- +" s:NFH_pdf: visualize pdf files {{{1 +fun! s:NFH_pdf(pdf) +" call Dfunc("s:NFH_pdf(pdf<".a:pdf.">)") + if executable("gs") + exe 'silent! !gs '.shellescape(a:pdf,1) + elseif executable("pdftotext") + exe 'silent! pdftotext -nopgbrk '.shellescape(a:pdf,1) + else +" call Dret("s:NFH_pdf 0") + return 0 + endif + +" call Dret("s:NFH_pdf 1") + return 1 +endfun + +" --------------------------------------------------------------------- +" s:NFH_doc: visualize doc files {{{1 +fun! s:NFH_doc(doc) +" call Dfunc("s:NFH_doc(doc<".a:doc.">)") + + if executable("oowriter") + exe 'silent! !oowriter '.shellescape(a:doc,1) + redraw! + else +" call Dret("s:NFH_doc 0") + return 0 + endif + +" call Dret("s:NFH_doc 1") + return 1 +endfun + +" --------------------------------------------------------------------- +" s:NFH_sxw: visualize sxw files {{{1 +fun! s:NFH_sxw(sxw) +" call Dfunc("s:NFH_sxw(sxw<".a:sxw.">)") + + if executable("oowriter") + exe 'silent! !oowriter '.shellescape(a:sxw,1) + redraw! + else +" call Dret("s:NFH_sxw 0") + return 0 + endif + +" call Dret("s:NFH_sxw 1") + return 1 +endfun + +" --------------------------------------------------------------------- +" s:NFH_xls: visualize xls files {{{1 +fun! s:NFH_xls(xls) +" call Dfunc("s:NFH_xls(xls<".a:xls.">)") + + if executable("oocalc") + exe 'silent! !oocalc '.shellescape(a:xls,1) + redraw! + else +" call Dret("s:NFH_xls 0") + return 0 + endif + +" call Dret("s:NFH_xls 1") + return 1 +endfun + +" --------------------------------------------------------------------- +" s:NFH_ps: handles PostScript files {{{1 +fun! s:NFH_ps(ps) +" call Dfunc("s:NFH_ps(ps<".a:ps.">)") + if executable("gs") +" call Decho("exe silent! !gs ".a:ps) + exe "silent! !gs ".shellescape(a:ps,1) + redraw! + elseif executable("ghostscript") +" call Decho("exe silent! !ghostscript ".a:ps) + exe "silent! !ghostscript ".shellescape(a:ps,1) + redraw! + elseif executable("gswin32") +" call Decho("exe silent! !gswin32 ".shellescape(a:ps,1)) + exe "silent! !gswin32 ".shellescape(a:ps,1) + redraw! + else +" call Dret("s:NFH_ps 0") + return 0 + endif + +" call Dret("s:NFH_ps 1") + return 1 +endfun + +" --------------------------------------------------------------------- +" s:NFH_eps: handles encapsulated PostScript files {{{1 +fun! s:NFH_eps(eps) +" call Dfunc("s:NFH_eps()") + if executable("gs") + exe "silent! !gs ".shellescape(a:eps,1) + redraw! + elseif executable("ghostscript") + exe "silent! !ghostscript ".shellescape(a:eps,1) + redraw! + elseif executable("ghostscript") + exe "silent! !ghostscript ".shellescape(a:eps,1) + redraw! + elseif executable("gswin32") + exe "silent! !gswin32 ".shellescape(a:eps,1) + redraw! + else +" call Dret("s:NFH_eps 0") + return 0 + endif +" call Dret("s:NFH_eps 0") + return 1 +endfun + +" --------------------------------------------------------------------- +" s:NFH_fig: handles xfig files {{{1 +fun! s:NFH_fig(fig) +" call Dfunc("s:NFH_fig()") + if executable("xfig") + exe "silent! !xfig ".a:fig + redraw! + else +" call Dret("s:NFH_fig 0") + return 0 + endif + +" call Dret("s:NFH_fig 1") + return 1 +endfun + +" --------------------------------------------------------------------- +" s:NFH_obj: handles tgif's obj files {{{1 +fun! s:NFH_obj(obj) +" call Dfunc("s:NFH_obj()") + if has("unix") && executable("tgif") + exe "silent! !tgif ".a:obj + redraw! + else +" call Dret("s:NFH_obj 0") + return 0 + endif + +" call Dret("s:NFH_obj 1") + return 1 +endfun + +let &cpo= s:keepcpo +" --------------------------------------------------------------------- +" Modelines: {{{1 +" vim: fdm=marker diff --git a/vimfiles/autoload/netrwSettings.vim b/vimfiles/autoload/netrwSettings.vim index acbd145..daf9e21 100644 --- a/vimfiles/autoload/netrwSettings.vim +++ b/vimfiles/autoload/netrwSettings.vim @@ -19,7 +19,13 @@ if exists("g:loaded_netrwSettings") || &cp finish endif -let g:loaded_netrwSettings = "v13" +let g:loaded_netrwSettings = "v13" +if v:version < 700 + echohl WarningMsg + echo "***warning*** this version of netrwSettings needs vim 7.0" + echohl Normal + finish +endif " --------------------------------------------------------------------- " NetrwSettings: {{{1 diff --git a/vimfiles/doc/Align.txt b/vimfiles/doc/Align.txt index a79a566..ce80238 100644 --- a/vimfiles/doc/Align.txt +++ b/vimfiles/doc/Align.txt @@ -1,1387 +1,1414 @@ -*align.txt* The Alignment Tool Mar 06, 2008 - -Author: Charles E. Campbell, Jr. - (remove NOSPAM from Campbell's email first) -Copyright: (c) 2004-2008 by Charles E. Campbell, Jr. *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. 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................: |align-align| - 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| - 4. Alignment Tool History...: |align-history| - -============================================================================== -2. Align Manual *alignman* *alignmanual* *align-manual* - - To Enable: put and into your .vim/plugin - To see a user's guide, see |align-usage| - 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 || -|| | | || -|| | 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* - - -ALIGNMENT CONCEPTS *align-concept* *align-concepts* - - 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" - (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 more options available for field justification: see - |alignctrl-c|. - - 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 wished. This wish is simply achieved with > - :AlignCtrl lr - :1,4Align = -< because the justification commands are considered to be "cylic"; 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* - - 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 PATTERNS:~ - Align and AlignCtrl use || to obtain their - input patterns; hence, to get a \ you'll need to enter - two backslashes: \\. - - 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. -< - -ALIGNMENT OPTIONS *align-option* *align-options* - - *align-utf8* *align-utf* *align-codepoint* *align-strlen* - For those of you who are using 2-byte (or more) characters such as is - available with utf-8, Align now provides a special option which you - may choose based upon your needs: - - Number of codepoints (Latin a + combining circumflex is two codepoints)~ -> - let g:Align_xstrlen= 1: -< - 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= 2 -< - By putting one of these settings into your <.vimrc>, Align will use an - internal (interpreted) function to determine a string's length instead - of the built-in to Vim's |strlen()| function. As the function is - interpreted, Align will run a bit slower but will handle such strings - correctly. The last setting (g:Align_xstrlen= 2) probably will run - the slowest but be the most accurate. - (thanks to Tony Mechelynck for these) - - -ALIGNMENT CONTROL *alignctrl* *align-control* - - This command doesn't do the alignment operation itself; instead, it - controls the subsequent alignment operation(s). - - The first argument to AlignCtrl is a string which may contain one or - more alignment control commands. Most of the commands are single - letter commands; the exceptions are the p# and P# commands which - interpret digits 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* - - 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. - - However, if you really need to have such 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() function 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* - --- *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* - ------ *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 "l"). - 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-:* - - 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. - - - --- *alignctrl-=* - =C CYCLIC VS ALL-ACTIVE SEPARATORS *alignctrl-C* - --- - - 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 - \(pat1\|pat2\|pat3\) -< - 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->* - --- *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 specification is 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* - --- - - - 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() 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 that 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 a plain AlignCtrl call: > - - AlignCtrl -< - - --- - m MAP SUPPORT *alignctrl-m* - --- - - This option primarily supports the development of maps. The AlignCtrl - call will first do an AlignPush() (ie. retain current alignment - control settings). The next Align() will, in addition to its - alignment job, finish up with an AlignPop(). Thus the AlignCtrl - settings that follow the "m" are only temporarily in effect for just - the next Align(). - - - --- - p### *alignctrl-p* - P### PADDING *alignctrl-P* - --- - - 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-* - --------------- *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. - - One may get a string which can be fed back into AlignCtrl: > - - :let alignctrl= AlignCtrl() -< - This form will put a string describing the current AlignCtrl options, - except for the "g" and "v" patterns, into a variable. The AlignCtrl() - function will still echo its settings, however. One can feed any - non-supported "option" to AlignCtrl() to prevent this, however: > - - :let alignctrl= AlignCtrl("d") -< - -ALIGNMENT *align-align* - - 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. - - -ALIGNMENT MAPS *alignmaps* *align-maps* - - There are a number of maps using AlignCtrl() and Align() in the - file. This file may also be put into the plugins - subdirectory. Since AlignCtrl and Align supercede textab and its - file, the maps either have a leading "t" (for "textab") - or the more complicated ones an "a" (for "alignment") for backwards - compatibility. - - \a, : useful for breaking up comma-separated - declarations prior to \adec |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://mysite.verizon.net/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 - \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| for 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 - selector. - - 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 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() 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 protect any original - embedded "@" symbols by first converting them to characters, - doing the requested job, and then converting them back. - - - --------------------------- - Alignment Map Examples: \a, *alignmap-a,* - --------------------------- - - 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?* - --------------------------- - - 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<* - --------------------------- - - 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=* - --------------------------- - - 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* - --------------------------- - - 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* - --------------------------- - - 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* - --------------------------- - - 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: 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 - - One may get \aenum behavior for \anum > - let g:alignmaps_euronumber= 1 -< or \aunum behavior for \anum if one puts > - let g:alignmaps_usanumber= 1 -< in one's <.vimrc>. - - - --------------------------- - Alignment Map Examples: \ascom *alignmap-ascom* - --------------------------- - - 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* - --------------------------- - - 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* - --------------------------- - - 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* - --------------------------- - - 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* - --------------------------- - - 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* - --------------------------- - - 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| - - - --------------------------- - Alignment Map Examples: \tsp *alignmap-tsp* - --------------------------- - - 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* - --------------------------- - - 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* - --------------------------- - - 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* - ---------------------------- - - 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=* - --------------------------- - - 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=* - --------------------------- - - 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* - --------------------------- - - 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 Tool History *align-history* {{{1 - -ALIGN HISTORY {{{2 - 33 : 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. - 32 : Aug 18, 2007 * uses || instead of || plus a - custom argument splitter to allow patterns with - backslashes to slide in unaltered. - 31 : Aug 06, 2007 * :[range]Align! [AlignCtrl settings] pattern(s) - implemented. - 30 : Feb 12, 2007 * now uses |setline()| - 29 : Jan 18, 2006 * cecutil updated to use keepjumps - Feb 23, 2006 * Align now converted to vim 7.0 style using - auto-loading functions. - 28 : Aug 17, 2005 * report option workaround - Oct 24, 2005 * AlignCtrl l: wasn't behaving as expected; fixed - 27 : Apr 15, 2005 : cpo workaround - ignorecase workaround - 26 : Aug 20, 2004 : loaded_align now also indicates version number - GetLatestVimScripts :AutoInstall: now supported - 25 : Jul 27, 2004 : For debugging, uses Dfunc(), Dret(), and Decho() - 24 : 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. - 23 : Oct 07, 2003 : Included Leif Wickland's ReplaceQuotedSpaces() - function which supports \tsq - 22 : Jan 29, 2003 : Now requires 6.1.308 or later to clear visualmode() - 21 : Jan 10, 2003 : BugFix: similar problem to #19; new code - bypasses "norm! v\" until initialization - is over. - 20 : Dec 30, 2002 : BugFix: more on "unable to highlight" fixed - 19 : 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. - 18 : Nov 04, 2002 : BugFix: re-enabled anti-repeated-loading - 17 : 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 '< '> - 16 : Sep 18, 2002 : AlignCtrl <>| options implemented (separator - justification) - 15 : Aug 22, 2002 : bug fix: AlignCtrl's ":" now acts as a modifier of - the preceding alignment operator (lrc) - 14 : 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 - 13 : 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 - 12 : 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 - 11 : Jul 08, 2002 : prevent separator patterns which match zero length - -+: included as additional alignment/justification - styles - 10 : Jun 26, 2002 : =~# used instead of =~ (for matching case) - ignorecase option handled - 9 : Jun 25, 2002 : implemented cyclic padding - -ALIGNMENT MAP HISTORY *alignmap-history* {{{2 - v39 Mar 06, 2008 : * \t= only does /* ... */ aligning when in *.c - *.cpp files. - v38 Aug 18, 2007 : * \tt altered so that it works with the new - use of || plus a custom argument - splitter - v36 Sep 27, 2006 : * AlignWrapperStart() now has tests that marks - y and z are not set - May 15, 2007 * \anum and variants improved - v35 Sep 01, 2006 : * \t= and cousins used "`"s. They now use \xff - characters. - * \acom now works with doxygen style /// comments - * used in \t= \T= \w= and \m= instead - of backquotes. - v34 Feb 23, 2006 : * AlignMaps now converted to vim 7.0 style using - auto-loading functions. - v33 Oct 12, 2005 : * \ts, now uses P1 in its AlignCtrl call - v32 Jun 28, 2005 : * s:WrapperStart() changed to AlignWrapperStart() - s:WrapperEnd() changed to AlignWrapperEnd() - These changes let the AlignWrapper...()s to be - used outside of AlignMaps.vim - v31 Feb 01, 2005 : * \adcom included, with help - * \a, now works across multiple lines with - different types - * AlignMaps now uses for its mark and - window-position saving and restoration - Mar 04, 2005 * improved \a, - Apr 06, 2005 * included \aenum, \aunum, and provided - g:alignmaps_{usa|euro]number} options - v30 Aug 20, 2004 : * \a, : handles embedded assignments and does \adec - * \acom now can handle Doxygen-style comments - * g:loaded_alignmaps now also indicates version - * internal maps \WE and \WS are now re-entrant - v29 Jul 27, 2004 : * \tml aligns trailing multi-line single - backslashes (thanks to Raul Benavente!) - v28 May 13, 2004 : * \a, had problems with leading blanks; fixed! - v27 Mar 31, 2004 : * \T= was having problems with == and != - * Fixed more problems with \adec - v26 Dec 09, 2003 : * \ascom now also ignores lines without comments - * \tt \& now not matched - * \a< handles both << and >> - v25 Nov 14, 2003 : * included \anum (aligns numbers with periods and - commas). \anum also supported with ctrl-v mode. - * \ts, \Ts, : (aligns on commas, then swaps leading - spaces with commas) - * \adec ignores preprocessor lines and lines with - with comments-only - v23 Sep 10, 2003 : * Bugfix for \afnc - no longer overwrites marks y,z - * fixed bug in \tsp, \tab, \Tsp, and \Tab - lines - containing backslashes were having their - backslashes removed. Included Leif Wickland's - patch for \tsq. - * \adef now ignores lines holding comments only - v18 Aug 22, 2003 : \a< lines up C++'s << operators - saves/restores gdefault option (sets to nogd) - all b:..varname.. are now b:alignmaps_..varname.. - v17 Nov 04, 2002 : \afnc now handles // comments correctly and - commas within comments - v16 Sep 10, 2002 : changed : to :silent! for \adec - v15 Aug 27, 2002 : removed some s - v14 Aug 20, 2002 : \WS, \WE mostly moved to functions, marks y and z - now restored - v11 Jul 08, 2002 : \abox bug fix - v9 Jun 25, 2002 : \abox now handles leading initial whitespace - : various bugfixes to \afnc, \T=, etc - -============================================================================== -Modelines: {{{1 -vim:tw=78:ts=8:ft=help:fdm=marker: +*align.txt* The Alignment Tool Oct 29, 2008 + +Author: Charles E. Campbell, Jr. + (remove NOSPAM from Campbell's email first) +Copyright: (c) 2004-2008 by Charles E. Campbell, Jr. *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................: |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 + + To Enable: put and into your .vim/plugin + To see a user's guide, see |align-usage| + 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 || +|| | | || +|| | 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* {{{1 + + +ALIGNMENT CONCEPTS *align-concept* *align-concepts* {{{2 + + 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" + (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 more options available for field justification: see + |alignctrl-c|. + + 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 wished. This wish is simply achieved with > + :AlignCtrl lr + :1,4Align = +< because the justification commands are considered to be "cylic"; 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. +< + +ALIGNMENT OPTIONS *align-option* *align-options* {{{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: + + Number of codepoints (Latin a + combining circumflex is two codepoints)~ +> + let g:Align_xstrlen= 1: +< + 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 +< + By putting one of these settings into your <.vimrc>, Align will use an + internal (interpreted) function to determine a string's length instead + of the Vim's built-in |strlen()| function. As the function is + interpreted, Align will run a bit slower but will handle such strings + correctly. The last setting (g:Align_xstrlen= 3) 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 the subsequent alignment operation(s). + + The first argument to AlignCtrl is a string which may contain one or + more alignment control commands. Most of the commands are single + letter commands; the exceptions are the p# and P# commands which + interpret digits 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. + + However, if you really need to have such 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 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 "l"). + 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-:* + + 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. + + + --- *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 + \(pat1\|pat2\|pat3\) +< + 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 specification is 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 that 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 a plain AlignCtrl call: > + + 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. + + 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 *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 using Align#AlignCtrl() and Align#Align() in the + file. This file may also be put into the plugins + subdirectory. Since AlignCtrl and Align supercede textab and its + file, the maps either have a leading "t" (for "textab") + or the more complicated ones an "a" (for "alignment") for backwards + compatibility. + + Thee maps are shown below with a leading backslash (\). Actually, + the construct is used (see :help mapleader), so the leading + map kick-off character is easily customized. + + Furthermore, all AlignMaps.vim maps use the construct (see + ||and | + 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 (...)? ...:... 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://mysite.verizon.net/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 + \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| for 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 + selector. + + 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 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 protect any original + embedded "@" symbols by first converting them to characters, + doing the requested job, and then converting them back. + + + --------------------------- + 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 + --------------------------- + + 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: 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 + + One may get \aenum behavior for \anum > + let g:alignmaps_euronumber= 1 +< or \aunum behavior for \anum if one puts > + 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| + + + --------------------------- + 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 Tool History *align-history* {{{1 + +ALIGN HISTORY {{{2 + 34 : Jul 08, 2008 * using :AlignCtrl before entering any alignment + control commands was causing an error. + 33 : 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. + 32 : Aug 18, 2007 * uses || instead of || plus a + custom argument splitter to allow patterns with + backslashes to slide in unaltered. + 31 : Aug 06, 2007 * :[range]Align! [AlignCtrl settings] pattern(s) + implemented. + 30 : Feb 12, 2007 * now uses |setline()| + 29 : Jan 18, 2006 * cecutil updated to use keepjumps + Feb 23, 2006 * Align now converted to vim 7.0 style using + auto-loading functions. + 28 : Aug 17, 2005 * report option workaround + Oct 24, 2005 * AlignCtrl l: wasn't behaving as expected; fixed + 27 : Apr 15, 2005 : cpo workaround + ignorecase workaround + 26 : Aug 20, 2004 : loaded_align now also indicates version number + GetLatestVimScripts :AutoInstall: now supported + 25 : Jul 27, 2004 : For debugging, uses Dfunc(), Dret(), and Decho() + 24 : 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. + 23 : Oct 07, 2003 : Included Leif Wickland's ReplaceQuotedSpaces() + function which supports \tsq + 22 : Jan 29, 2003 : Now requires 6.1.308 or later to clear visualmode() + 21 : Jan 10, 2003 : BugFix: similar problem to #19; new code + bypasses "norm! v\" until initialization + is over. + 20 : Dec 30, 2002 : BugFix: more on "unable to highlight" fixed + 19 : 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. + 18 : Nov 04, 2002 : BugFix: re-enabled anti-repeated-loading + 17 : 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 '< '> + 16 : Sep 18, 2002 : AlignCtrl <>| options implemented (separator + justification) + 15 : Aug 22, 2002 : bug fix: AlignCtrl's ":" now acts as a modifier of + the preceding alignment operator (lrc) + 14 : 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 + 13 : 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 + 12 : 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 + 11 : Jul 08, 2002 : prevent separator patterns which match zero length + -+: included as additional alignment/justification + styles + 10 : Jun 26, 2002 : =~# used instead of =~ (for matching case) + ignorecase option handled + 9 : Jun 25, 2002 : implemented cyclic padding + +ALIGNMENT MAP HISTORY *alignmap-history* {{{2 + v40 Oct 21, 2008 * Modified AlignMaps so that its maps use s + and