1 " Vimball Archiver by Charles E. Campbell, Jr., Ph.D.
4 plugin/cecutil.vim [[[1
6 " cecutil.vim : save/restore window position
7 " save/restore mark position
8 " save/restore selected user maps
9 " Author: Charles E. Campbell, Jr.
13 " Saving Restoring Destroying Marks: {{{1
14 " call SaveMark(markname) let savemark= SaveMark(markname)
15 " call RestoreMark(markname) call RestoreMark(savemark)
16 " call DestroyMark(markname)
19 " Saving Restoring Destroying Window Position: {{{1
20 " call SaveWinPosn() let winposn= SaveWinPosn()
21 " call RestoreWinPosn() call RestoreWinPosn(winposn)
22 " \swp : save current window/buffer's position
23 " \rwp : restore current window/buffer's previous position
26 " Saving And Restoring User Maps: {{{1
27 " call SaveUserMaps(mapmode,maplead,mapchx,suffix)
28 " call RestoreUserMaps(suffix)
30 " GetLatestVimScripts: 1066 1 :AutoInstall: cecutil.vim
32 " You believe that God is one. You do well. The demons also {{{1
33 " believe, and shudder. But do you want to know, vain man, that
34 " faith apart from works is dead? (James 2:19,20 WEB)
37 if &cp || exists("g:loaded_cecutil")
40 let g:loaded_cecutil = "v16"
45 " -----------------------
46 " Public Interface: {{{1
47 " -----------------------
50 if !hasmapto('<Plug>SaveWinPosn')
51 map <unique> <Leader>swp <Plug>SaveWinPosn
53 if !hasmapto('<Plug>RestoreWinPosn')
54 map <unique> <Leader>rwp <Plug>RestoreWinPosn
56 nmap <silent> <Plug>SaveWinPosn :call SaveWinPosn()<CR>
57 nmap <silent> <Plug>RestoreWinPosn :call RestoreWinPosn()<CR>
59 " Command Interface: {{{2
60 com! -bar -nargs=0 SWP call SaveWinPosn()
61 com! -bar -nargs=0 RWP call RestoreWinPosn()
62 com! -bar -nargs=1 SM call SaveMark(<q-args>)
63 com! -bar -nargs=1 RM call RestoreMark(<q-args>)
64 com! -bar -nargs=1 DM call DestroyMark(<q-args>)
67 let s:modifier= "sil "
69 let s:modifier= "sil keepj "
72 " ---------------------------------------------------------------------
74 " let winposn= SaveWinPosn() will save window position in winposn variable
75 " call SaveWinPosn() will save window position in b:cecutil_winposn{b:cecutil_iwinposn}
76 " let winposn= SaveWinPosn(0) will *only* save window position in winposn variable (no stacking done)
78 " call Dfunc("SaveWinPosn() a:0=".a:0)
79 if line(".") == 1 && getline(1) == ""
80 " call Dfunc("SaveWinPosn : empty buffer")
88 let swline = line(".")
90 let swwline = winline() - 1
91 let swwcol = virtcol(".") - wincol()
92 let savedposn = "call GoWinbufnr(".winbufnr(0).")|silent ".swline
93 let savedposn = savedposn."|".s:modifier."norm! 0z\<cr>"
95 let savedposn= savedposn.":".s:modifier."norm! ".swwline."\<c-y>\<cr>"
98 let savedposn= savedposn.":".s:modifier."norm! 0".swwcol."zl\<cr>"
100 let savedposn = savedposn.":".s:modifier."call cursor(".swline.",".swcol.")\<cr>"
102 " save window position in
103 " b:cecutil_winposn_{iwinposn} (stack)
104 " only when SaveWinPosn() is used
106 if !exists("b:cecutil_iwinposn")
107 let b:cecutil_iwinposn= 1
109 let b:cecutil_iwinposn= b:cecutil_iwinposn + 1
111 " call Decho("saving posn to SWP stack")
112 let b:cecutil_winposn{b:cecutil_iwinposn}= savedposn
116 let &siso = siso_keep
119 " if exists("b:cecutil_iwinposn") " Decho
120 " call Decho("b:cecutil_winpos{".b:cecutil_iwinposn."}[".b:cecutil_winposn{b:cecutil_iwinposn}."]")
122 " call Decho("b:cecutil_iwinposn doesn't exist")
124 " call Dret("SaveWinPosn [".savedposn."]")
128 " ---------------------------------------------------------------------
129 " RestoreWinPosn: {{{1
130 fun! RestoreWinPosn(...)
131 " call Dfunc("RestoreWinPosn() a:0=".a:0)
132 " call Decho("getline(1)<".getline(1).">")
133 " call Decho("line(.)=".line("."))
134 if line(".") == 1 && getline(1) == ""
135 " call Dfunc("RestoreWinPosn : empty buffer")
139 let siso_keep = &siso
143 if a:0 == 0 || a:1 == ""
144 " use saved window position in b:cecutil_winposn{b:cecutil_iwinposn} if it exists
145 if exists("b:cecutil_iwinposn") && exists("b:cecutil_winposn{b:cecutil_iwinposn}")
146 " call Decho("using stack b:cecutil_winposn{".b:cecutil_iwinposn."}<".b:cecutil_winposn{b:cecutil_iwinposn}.">")
148 exe "silent! ".b:cecutil_winposn{b:cecutil_iwinposn}
149 catch /^Vim\%((\a\+)\)\=:E749/
150 " ignore empty buffer error messages
152 " normally drop top-of-stack by one
153 " but while new top-of-stack doesn't exist
154 " drop top-of-stack index by one again
155 if b:cecutil_iwinposn >= 1
156 unlet b:cecutil_winposn{b:cecutil_iwinposn}
157 let b:cecutil_iwinposn= b:cecutil_iwinposn - 1
158 while b:cecutil_iwinposn >= 1 && !exists("b:cecutil_winposn{b:cecutil_iwinposn}")
159 let b:cecutil_iwinposn= b:cecutil_iwinposn - 1
161 if b:cecutil_iwinposn < 1
162 unlet b:cecutil_iwinposn
167 echomsg "***warning*** need to SaveWinPosn first!"
171 else " handle input argument
172 " call Decho("using input a:1<".a:1.">")
173 " use window position passed to this function
175 " remove a:1 pattern from b:cecutil_winposn{b:cecutil_iwinposn} stack
176 if exists("b:cecutil_iwinposn")
177 let jwinposn= b:cecutil_iwinposn
178 while jwinposn >= 1 " search for a:1 in iwinposn..1
179 if exists("b:cecutil_winposn{jwinposn}") " if it exists
180 if a:1 == b:cecutil_winposn{jwinposn} " and the pattern matches
181 unlet b:cecutil_winposn{jwinposn} " unlet it
182 if jwinposn == b:cecutil_iwinposn " if at top-of-stack
183 let b:cecutil_iwinposn= b:cecutil_iwinposn - 1 " drop stacktop by one
187 let jwinposn= jwinposn - 1
192 " seems to be something odd: vertical motions after RWP
193 " cause jump to first column. Following fixes that
196 elseif virtcol(".") < virtcol("$")
201 let &siso = siso_keep
204 " call Dret("RestoreWinPosn")
207 " ---------------------------------------------------------------------
208 " GoWinbufnr: go to window holding given buffer (by number) {{{1
209 " Prefers current window; if its buffer number doesn't match,
210 " then will try from topleft to bottom right
211 fun! GoWinbufnr(bufnum)
212 " call Dfunc("GoWinbufnr(".a:bufnum.")")
213 if winbufnr(0) == a:bufnum
214 " call Dret("GoWinbufnr : winbufnr(0)==a:bufnum")
219 while winbufnr(0) != a:bufnum && (first || winnr() != 1)
223 " call Dret("GoWinbufnr")
226 " ---------------------------------------------------------------------
227 " SaveMark: sets up a string saving a mark position. {{{1
228 " For example, SaveMark("a")
229 " Also sets up a global variable, g:savemark_{markname}
230 fun! SaveMark(markname)
231 " call Dfunc("SaveMark(markname<".a:markname.">)")
232 let markname= a:markname
233 if strpart(markname,0,1) !~ '\a'
234 let markname= strpart(markname,1,1)
236 " call Decho("markname=".markname)
241 if 1 <= line("'".markname) && line("'".markname) <= line("$")
242 let winposn = SaveWinPosn(0)
243 exe s:modifier."norm! `".markname
244 let savemark = SaveWinPosn(0)
245 let g:savemark_{markname} = savemark
246 let savemark = markname.savemark
247 call RestoreWinPosn(winposn)
249 let g:savemark_{markname} = ""
255 " call Dret("SaveMark : savemark<".savemark.">")
259 " ---------------------------------------------------------------------
261 " call RestoreMark("a") -or- call RestoreMark(savemark)
262 fun! RestoreMark(markname)
263 " call Dfunc("RestoreMark(markname<".a:markname.">)")
265 if strlen(a:markname) <= 0
266 " call Dret("RestoreMark : no such mark")
269 let markname= strpart(a:markname,0,1)
271 " handles 'a -> a styles
272 let markname= strpart(a:markname,1,1)
274 " call Decho("markname=".markname." strlen(a:markname)=".strlen(a:markname))
278 let winposn = SaveWinPosn(0)
280 if strlen(a:markname) <= 2
281 if exists("g:savemark_{markname}") && strlen(g:savemark_{markname}) != 0
282 " use global variable g:savemark_{markname}
283 " call Decho("use savemark list")
284 call RestoreWinPosn(g:savemark_{markname})
285 exe "norm! m".markname
288 " markname is a savemark command (string)
289 " call Decho("use savemark command")
290 let markcmd= strpart(a:markname,1)
291 call RestoreWinPosn(markcmd)
292 exe "norm! m".markname
295 call RestoreWinPosn(winposn)
298 " call Dret("RestoreMark")
301 " ---------------------------------------------------------------------
303 " call DestroyMark("a") -- destroys mark
304 fun! DestroyMark(markname)
305 " call Dfunc("DestroyMark(markname<".a:markname.">)")
307 " save options and set to standard values
308 let reportkeep= &report
312 let markname= strpart(a:markname,0,1)
314 " handles 'a -> a styles
315 let markname= strpart(a:markname,1,1)
317 " call Decho("markname=".markname)
320 let winposn = SaveWinPosn(0)
322 let lineone = getline(".")
327 call RestoreWinPosn(winposn)
329 " restore options to user settings
330 let &report = reportkeep
333 " call Dret("DestroyMark")
336 " ---------------------------------------------------------------------
338 "fun! ListWinPosn() " Decho
339 " if !exists("b:cecutil_iwinposn") || b:cecutil_iwinposn == 0 " Decho
340 " call Decho("nothing on SWP stack") " Decho
342 " let jwinposn= b:cecutil_iwinposn " Decho
343 " while jwinposn >= 1 " Decho
344 " if exists("b:cecutil_winposn{jwinposn}") " Decho
345 " call Decho("winposn{".jwinposn."}<".b:cecutil_winposn{jwinposn}.">") " Decho
347 " call Decho("winposn{".jwinposn."} -- doesn't exist") " Decho
349 " let jwinposn= jwinposn - 1 " Decho
353 "com! -nargs=0 LWP call ListWinPosn() " Decho
355 " ---------------------------------------------------------------------
356 " SaveUserMaps: this function sets up a script-variable (s:restoremap) {{{1
357 " which can be used to restore user maps later with
358 " call RestoreUserMaps()
360 " mapmode - see :help maparg for its list
362 " If the first letter is u, then unmapping will be done
363 " ex. "un" = Normal + unmapping
364 " maplead - see mapchx
365 " mapchx - "<something>" handled as a single map item.
367 " - "string" a string of single letters which are actually
368 " multiple two-letter maps (using the maplead:
369 " maplead . each_character_in_string)
370 " ex. maplead="\" and mapchx="abc" saves user mappings for
372 " Of course, if maplead is "", then for mapchx="abc",
373 " mappings for a, b, and c are saved.
374 " - :something handled as a single map item, w/o the ":"
375 " ex. mapchx= ":abc" will save a mapping for "abc"
376 " suffix - a string unique to your plugin
377 " ex. suffix= "DrawIt"
378 fun! SaveUserMaps(mapmode,maplead,mapchx,suffix)
379 " call Dfunc("SaveUserMaps(mapmode<".a:mapmode."> maplead<".a:maplead."> mapchx<".a:mapchx."> suffix<".a:suffix.">)")
381 if !exists("s:restoremap_{a:suffix}")
382 " initialize restoremap_suffix to null string
383 let s:restoremap_{a:suffix}= ""
386 " set up dounmap: if 1, then save and unmap (a:mapmode leads with a "u")
390 let mapmode= strpart(a:mapmode,1)
393 let mapmode= a:mapmode
396 " save single map :...something...
397 if strpart(a:mapchx,0,1) == ':'
398 let amap= strpart(a:mapchx,1)
399 if amap == "|" || amap == "\<c-v>"
400 let amap= "\<c-v>".amap
402 let amap = a:maplead.amap
403 let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|:silent! ".mapmode."unmap ".amap
404 if maparg(amap,mapmode) != ""
405 let maprhs = substitute(maparg(amap,mapmode),'|','<bar>','ge')
406 let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|:".mapmode."map ".amap." ".maprhs
409 exe "silent! ".mapmode."unmap ".amap
412 " save single map <something>
413 elseif strpart(a:mapchx,0,1) == '<'
415 if amap == "|" || amap == "\<c-v>"
416 let amap= "\<c-v>".amap
418 let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|silent! ".mapmode."unmap ".amap
419 if maparg(a:mapchx,mapmode) != ""
420 let maprhs = substitute(maparg(amap,mapmode),'|','<bar>','ge')
421 let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|".mapmode."map ".amap." ".maprhs
424 exe "silent! ".mapmode."unmap ".amap
430 while i <= strlen(a:mapchx)
431 let amap= a:maplead.strpart(a:mapchx,i-1,1)
432 if amap == "|" || amap == "\<c-v>"
433 let amap= "\<c-v>".amap
435 let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|silent! ".mapmode."unmap ".amap
436 if maparg(amap,mapmode) != ""
437 let maprhs = substitute(maparg(amap,mapmode),'|','<bar>','ge')
438 let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|".mapmode."map ".amap." ".maprhs
441 exe "silent! ".mapmode."unmap ".amap
446 " call Dret("SaveUserMaps : restoremap_".a:suffix.": ".s:restoremap_{a:suffix})
449 " ---------------------------------------------------------------------
450 " RestoreUserMaps: {{{1
451 " Used to restore user maps saved by SaveUserMaps()
452 fun! RestoreUserMaps(suffix)
453 " call Dfunc("RestoreUserMaps(suffix<".a:suffix.">)")
454 if exists("s:restoremap_{a:suffix}")
455 let s:restoremap_{a:suffix}= substitute(s:restoremap_{a:suffix},'|\s*$','','e')
456 if s:restoremap_{a:suffix} != ""
457 " call Decho("exe ".s:restoremap_{a:suffix})
458 exe "silent! ".s:restoremap_{a:suffix}
460 unlet s:restoremap_{a:suffix}
462 " call Dret("RestoreUserMaps")
465 " ---------------------------------------------------------------------
470 " ---------------------------------------------------------------------
472 " vim: ts=4 fdm=marker
473 plugin/AutoAlign.vim [[[1
475 " AutoAlign.vim: a ftplugin for C
476 " Author: Charles E. Campbell, Jr. <NdrOchip@ScampbellPfamily.AbizM>-NOSPAM
479 " GetLatestVimScripts: 884 1 :AutoInstall: AutoAlign.vim
480 " GetLatestVimScripts: 294 1 :AutoInstall: Align.vim
481 " GetLatestVimScripts: 1066 1 :AutoInstall: cecutil.vim
482 " ---------------------------------------------------------------------
484 if exists("b:didautoalign")
487 let b:loaded_autoalign = "v13"
491 " ---------------------------------------------------------------------
492 " Support Plugin Loading: {{{1
493 " insure that cecutil's SaveWinPosn/RestoreWinPosn has been loaded
494 if !exists("*SaveWinPosn")
495 silent! runtime plugin/cecutil.vim
498 " ---------------------------------------------------------------------
499 " Public Interface: AA toggles AutoAlign {{{1
500 com! -nargs=0 AA let b:autoalign= exists("b:autoalign")? !b:autoalign : 0|echo "AutoAlign is ".(b:autoalign? "on" : "off")
502 " ---------------------------------------------------------------------
503 " AutoAlign: decides when to use Align/AlignMap {{{1
504 " |i| : use b:autoalign_reqdpat{|i|} (ie. the i'th required pattern)
505 " and b:autoalign_notpat{|i|} (ie. the i'th not-pattern)
506 " i<0 : trigger character has been encountered, but don't AutoAlign
507 " if the reqdpat isn't present
509 " call Dfunc("AutoAlign(i=".a:i.") virtcol=".virtcol("."))
510 call s:SaveUserSettings()
512 " AutoAlign uses b:autoalign_reqdpat{|i|} and b:autoalign_notpat{|i|}
513 " A negative a:i means that a trigger character has been encountered,
514 " but not to AutoAlign if the reqdpat isn't present.
515 let i= (a:i < 0)? -a:i : a:i
516 if exists("b:autoalign") && b:autoalign == 0
517 call s:RestoreUserSettings()
518 " call Dret("AutoAlign : case b:autoalign==0")
522 " sanity check: must have a reqdpat
523 if !exists("b:autoalign_reqdpat{i}")
524 call s:RestoreUserSettings()
525 " call Dret("AutoAlign : b:autoalign_reqdpat{".i."} doesn't exist")
528 " call Decho("has reqdpat: match(<".getline(".").">,reqdpat<".b:autoalign_reqdpat{i}.">) = ".match(getline("."),b:autoalign_reqdpat{i}))
530 " set up some options for AutoAlign
535 if match(getline("."),b:autoalign_reqdpat{i}) >= 0
536 " call Decho("current line matches b:autoalign_reqdpat{".i."}<".b:autoalign_reqdpat{i}.">")
537 let curline = line(".")
539 let curposn = SaveWinPosn(0)
540 let nopatline = search(b:autoalign_notpat{i},'bW')
541 call RestoreWinPosn(curposn)
543 let nopatline = search(b:autoalign_notpat{i},'bWn')
546 " call Decho("nopatline=".nopatline." (using autoalign_notpat<".b:autoalign_notpat{i}.">)")
547 " call Decho("b:autoalign (".(exists("b:autoalign")? "exists" : "doesn't exist").")")
548 " call Decho("line('a)=".line("'a")." b:autoalign=".(exists("b:autoalign")? b:autoalign : -1)." curline=".curline." nopatline=".nopatline)
550 if exists("b:autoalign") && line("'a") == b:autoalign && b:autoalign < curline && nopatline < line("'a")
551 " call Decho("autoalign multi : b:autoalign_cmd{".i."}<".b:autoalign_cmd{i}.">")
552 " break undo sequence and start new change
553 " exe "norm! i\<c-g>u\<esc>" " cec 08/10/07 -- not sure if this is needed anymore
554 let curline= line(".")
555 exe b:autoalign_cmd{i}
556 exe curline."norm! $"
557 " call Decho('norm! lF'.b:autoalign_trigger{i}.'l')
558 exe 'norm! lF'.b:autoalign_trigger{i}.'l'
560 let b:autoalign= line(".")
562 " call Decho('norm! lF'.b:autoalign_trigger{i}.'l')
563 exe 'norm! lF'.b:autoalign_trigger{i}.'l'
564 " call Decho("autoalign start")
567 elseif exists("b:autoalign")
568 " trigger character encountered, but reqdpat not present
569 " call Decho("trigger char present, but doesn't match b:autoalign_reqdpat{".i."}<".b:autoalign_reqdpat{i}.">")
572 " call Decho("autoalign suspend")
575 elseif exists("b:autoalign_suspend{i}")
576 " trigger character encounted, but reqdpat not present, but takes more than
578 " call Decho("trigger char present, doesn't match b:autoalign_reqdpat{".i."}<".b:autoalign_reqdpat{i}.">, takes more than one trigger")
579 if match(getline("."),b:autoalign_suspend{i}) >= 0
581 " call Decho("autoalign suspend: matches autoalign_suspend<".b:autoalign_suspend{i}.">")
584 " call Decho("b:autoalign_reqdpat{".i."} doesn't match, b:autoalign doesn't exist, b:autoalign_suspend{".i."} doesn't exist")
587 " call Decho("(resume) exe norm! lF".b:autoalign_trigger{i}."l")
588 exe "norm! lF".b:autoalign_trigger{i}."l"
589 call s:RestoreUserSettings()
592 " call Dret("AutoAlign : @.<".@..">")
596 " ---------------------------------------------------------------------
597 " SaveUserSettings: {{{1
598 fun! s:SaveUserSettings()
599 " call Dfunc("SaveUserSettings()")
601 let b:keep_magic= &magic
602 let b:keep_remap= &remap
604 setlocal magic lz ve=all remap
605 " call Dret("SaveUserSettings")
608 " ---------------------------------------------------------------------
609 " RestoreUserSettings: {{{1
610 fun! s:RestoreUserSettings()
611 " call Dfunc("RestoreUserSettings()")
612 let &l:lz = b:keep_lz
613 let &l:magic = b:keep_magic
614 let &l:remap = b:keep_remap
615 let &l:ve = b:keep_ve
616 " call Dret("RestoreUserSettings")
621 " ---------------------------------------------------------------------
622 " vim: ts=4 fdm=marker
623 ftplugin/bib/AutoAlign.vim [[[1
625 " AutoAlign: ftplugin support for bib
626 " Author: Charles E. Campbell, Jr.
629 " ---------------------------------------------------------------------
630 let b:loaded_autoalign_bib= "v13"
631 "call Decho("loaded ftplugin/bib/AutoAlign!")
632 let b:undo_ftplugin= "v13"
634 " overloading '=' to keep things lined up {{{1
635 ino <silent> = =<c-r>=AutoAlign(1)<cr>
636 let b:autoalign_reqdpat1= '^\(\s*\h\w*\(\[\d\+]\)\{0,}\(->\|\.\)\=\)\+\s*[-+*/^|%]\=='
637 let b:autoalign_notpat1 = '^[^=]\+$'
638 let b:autoalign_trigger1= '='
639 if !exists("g:mapleader")
640 let b:autoalign_cmd1 = 'norm \t=$'
642 let b:autoalign_cmd1 = "norm ".g:mapleader."t=$"
644 ftplugin/c/AutoAlign.vim [[[1
646 " AutoAlign: ftplugin support for C
647 " Author: Charles E. Campbell, Jr.
650 " ---------------------------------------------------------------------
651 let b:loaded_autoalign_c = "v13"
652 let b:undo_ftplugin = "v13"
654 " overloading '=' to keep things lined up {{{1
655 ino <silent> = =<c-r>=AutoAlign(1)<cr>
656 let b:autoalign_reqdpat1 = '^\(\s*\*\{0,}\h\w*\%(\[\%(\d\+\|\h\w*\)]\)\{0,}\%(->\|\.\)\=\)\+\s*[-+*/^|%]\=='
657 let b:autoalign_notpat1 = '^[^=]\+$'
658 let b:autoalign_trigger1 = '='
659 if !exists("g:mapleader")
660 let b:autoalign_cmd1 = 'undojoin|norm \t=$'
662 let b:autoalign_cmd1 = "norm ".g:mapleader."t=$"
664 ftplugin/cpp/AutoAlign.vim [[[1
666 " AutoAlign: ftplugin support for C++
667 " Author: Charles E. Campbell, Jr.
670 " ---------------------------------------------------------------------
671 let b:loaded_autoalign_cpp= "v13"
672 let b:undo_ftplugin= "v13"
674 " overloading '=' to keep things lined up {{{1
675 ino <silent> = =<c-r>=AutoAlign(1)<cr>
676 let b:autoalign_reqdpat1 = '^\(\s*\h\w*\(\[\d\+]\)\{0,}\(->\|\.\)\=\)\+\s*[-+*/^|%]\=='
677 let b:autoalign_notpat1 = '^[^=]\+$'
678 let b:autoalign_trigger1 = '='
679 if !exists("g:mapleader")
680 let b:autoalign_cmd1 = 'norm \t=$'
682 let b:autoalign_cmd1 = "norm ".g:mapleader."t=$"
685 " overloading '<<' to keep things lined up {{{1
686 "ino <silent> < <<c-o>:silent call AutoAlign(-2)<cr>
687 ino <silent> < <<c-r>=AutoAlign(-2)<cr>
688 let b:autoalign_reqdpat2 = '<<'
689 let b:autoalign_notpat2 = '^\%(\%(<<\)\@!.\)*$'
690 let b:autoalign_trigger2 = '<'
691 if !exists("g:mapleader")
692 let b:autoalign_cmd2 = 'norm \a<$'
694 let b:autoalign_cmd2 = "norm ".g:mapleader."a<$"
697 " overloading '>>' to keep things lined up {{{1
698 "ino <silent> > ><c-o>:silent call AutoAlign(-3)<cr>
699 ino <silent> > ><c-r>=AutoAlign(-3)<cr>
700 let b:autoalign_reqdpat3 = '>>'
701 let b:autoalign_notpat3 = '^\%(\%(>>\)\@!.\)*$'
702 let b:autoalign_trigger3 = '>'
703 if !exists("g:mapleader")
704 let b:autoalign_cmd3 = 'norm \a<$'
706 let b:autoalign_cmd3 = "norm ".g:mapleader."a<$"
708 ftplugin/html/AutoAlign.vim [[[1
710 " AutoAlign: ftplugin support for HTML
711 " Author: Charles E. Campbell, Jr.
714 " ---------------------------------------------------------------------
715 let b:loaded_autoalign_html= "v13"
716 let b:undo_ftplugin= "v13"
718 " overloading '>' to keep things lined up {{{1
719 ino <silent> > ><c-r>=AutoAlign(-1)<cr>
720 let b:autoalign_reqdpat1 = '</[tT][rR]>$'
721 let b:autoalign_notpat1 = '\%(</[tT][rR]>\)\@!.\{5}$'
722 let b:autoalign_suspend1 = '\c</\=table>'
723 let b:autoalign_trigger1 = '>'
724 if !exists("g:mapleader")
725 let b:autoalign_cmd1 = 'norm \Htd$'
727 let b:autoalign_cmd1 = "norm ".g:mapleader."\Htd$"
729 ftplugin/maple/AutoAlign.vim [[[1
731 " AutoAlign: ftplugin support for Maple
732 " Author: Charles E. Campbell, Jr.
735 " ---------------------------------------------------------------------
736 let b:loaded_autoalign_maple = "v14"
737 let b:undo_ftplugin= "v13b"
739 " overloading '=' to keep things lined up {{{1
740 ino <silent> = =<c-r>=AutoAlign(1)<cr>
741 let b:autoalign_reqdpat1 = ':='
742 let b:autoalign_notpat1 = '^\%(\%(:=\)\@!.\)*$'
743 let b:autoalign_trigger1 = '='
744 let b:autoalign_cmd1 = "'a,.Align :="
745 ftplugin/matlab/AutoAlign.vim [[[1
747 " AutoAlign: ftplugin support for MatLab
748 " Author: Charles E. Campbell, Jr.
751 " ---------------------------------------------------------------------
752 let b:loaded_autoalign_matlab = "v13"
753 let b:undo_ftplugin= "v13"
755 " overloading '=' to keep things lined up {{{1
756 ino <silent> = =<c-r>=AutoAlign(1)<cr>
757 let b:autoalign_reqdpat1 = '\%(^.*=\)\&\%(^\s*\%(\%(if\>\|elseif\>\|function\>\|while\>\|for\>\)\@!.\)*$\)'
758 let b:autoalign_notpat1 = '^[^=]\+$'
759 let b:autoalign_trigger1 = '='
760 if !exists("g:mapleader")
761 let b:autoalign_cmd1 = 'norm \t=$'
763 let b:autoalign_cmd1 = "norm ".g:mapleader."t=$"
765 ftplugin/tex/AutoAlign.vim [[[1
767 " AutoAlign: ftplugin support for LaTeX
768 " Author: Charles E. Campbell, Jr.
771 " ---------------------------------------------------------------------
772 let b:loaded_autoalign_tex = "v13"
773 let b:undo_ftplugin= "v13"
775 " overloading '\' to keep things lined up {{{1
776 "ino <silent> \\ \\<c-o>:silent call AutoAlign(1)<cr>
777 ino <silent> \\ \\<c-r>=AutoAlign(1)<cr>
778 let b:autoalign_reqdpat1 = '^\([^&]*&\)\+[^&]*\\\{2}'
779 let b:autoalign_notpat1 = '^.*\(\\\\\)\@<!$\&^.'
780 let b:autoalign_trigger1 = '\\'
781 if !exists("g:mapleader")
782 let b:autoalign_cmd1 = 'norm \tt$'
784 let b:autoalign_cmd1 = "norm ".g:mapleader."tt$"
786 ftplugin/vim/AutoAlign.vim [[[1
788 " AutoAlign: ftplugin support for vim
789 " Author: Charles E. Campbell, Jr.
792 " ---------------------------------------------------------------------
793 let b:loaded_autoalign_vim = "v13"
794 let b:undo_ftplugin= "v13"
796 " overloading '=' to keep things lined up {{{1
797 "ino <silent> = =<c-o>:silent call AutoAlign(1)<cr>
798 ino <silent> = =<c-r>=AutoAlign(1)<cr>
799 let b:autoalign_reqdpat1 = '^\s*let\>.*='
800 let b:autoalign_notpat1 = '^[^=]\+$'
801 let b:autoalign_trigger1 = '='
802 if !exists("g:mapleader")
803 let b:autoalign_cmd1 = 'norm \t=$'
805 let b:autoalign_cmd1 = "norm ".g:mapleader."t=$"
807 doc/AutoAlign.txt [[[1
809 *autoalign.txt* Automatic Alignment Oct 19, 2006
811 Author: Charles E. Campbell, Jr. <NdrOchip@ScampbellPfamily.AbizM>
812 (remove NOSPAM from Campbell's email first)
813 Copyright: (c) 2004-2006 by Charles E. Campbell, Jr. *autoalign-copyright*
814 The VIM LICENSE applies to AutoAlign.vim and AutoAlign.txt
815 (see |copyright|) except use "AutoAlign" instead of "Vim"
816 No warranty, express or implied. Use At-Your-Own-Risk.
818 ==============================================================================
819 1. Contents *autoalign* *autoalign-contents*
821 1. Contents.................: |autoalign-contents|
822 2. Installing...............: |autoalign-install|
823 3. Alignment Manual.........: |autoalign-manual|
824 4. AutoAlign Internals......: |autoalign-internals|
825 5. AutoAlign History........: |autoalign-history|
827 ==============================================================================
828 2. Installing AutoAlign *autoalign-install*
830 1. AutoAlign needs the Align/AlignMaps utilities
831 which are available from either:
833 http://vim.sourceforge.net/scripts/script.php?script_id=294
834 http://mysite.verizon.net/astronaut/vim/textab.html
836 a) Put the compressed archive (Align.tar.gz) in your
837 .vim (Unix) or vimfiles\ (Windows) directory
838 b) Decompress it: gunzip Align.tar.gz
839 c) De-archive it: tar -oxvf Align.tar
842 2. AutoAlign is composed of a plugin and several
843 ftplugins. It is available from:
845 http://vim.sourceforge.net/scripts/script.php?script_id=884
847 3. Decompress it: gunzip Align.tar.gz
848 4. De-archive it: tar -oxvf Align.tar
849 5. Steps 3 and 4 will provide you with:
852 ftplugin/bib/AutoAlign.vim
853 ftplugin/c/AutoAlign.vim
854 ftplugin/cpp/AutoAlign.vim
855 ftplugin/maple/AutoAlign.vim
856 ftplugin/tex/AutoAlign.vim
857 ftplugin/vim/AutoAlign.vim
859 6. In order to make help available while using vim for AutoAlign:
862 :helptags ~/.vim/doc <-- Unix
863 :helptags (wherever)/vimfiles/doc <-- Windows
867 7. To enable plugins and filetype plugins generally, including
868 AutoAlign, have the following in your <.vimrc> file:
873 filetype plugin indent on
877 ==============================================================================
878 3. AutoAlign Manual *autoalign-man*
880 The AutoAlign filetype plugins operate while vim is in insert mode. They
881 apply appropriate Align/AlignMaps to the most recent contiguous region,
882 thereby keeping such things as "=" aligned. See |align| and |alignmaps|.
884 :AA - toggles AutoAlign on and off
886 The mark 'a is used by AutoAlign to indicate where the start of the
887 automatic alignment region begins. Changing 'a to some other place will
888 also stop AutoAlign from operating on that region. One may temporarily
889 suppress AutoAlignment that way.
891 Language AutoAlignment AutoAlignment
893 -------- ------------- -------------
903 The AutoAlignment trigger character invokes a call to the appropriate
904 filetype's AutoAlign. Only when:
906 * the current line matches a filetype specific pattern (to avoid
907 aligning <= >= == etc)
909 * the b:autoalign_vim variable records the first line which
910 satisfied the filetype specific pattern in the current
911 region. If it matches the mark ('a)'s line, then AutoAlignment
912 will occur. Thus the user can temporarily disable AutoAlignment
913 on the current region merely by changing where the mark 'a is
916 * Although frequently the trigger character is also used in
917 the alignment, sometimes a longer pattern is used (ex. maple's
920 The AutoAlign plugin is fairly trivial to use -- just type. Alignment
921 will occur for the following patterns automatically. These patterns
922 are stored in b:autoalign_reqdpat1, b:autoalign_reqdpat2, etc.
926 bib ^\(\s*\h\w*\(\[\d\+]\)\{0,}\(->\|\.\)\=\)\+\s*[-+*/^|%]\==
927 c ^\(\s*\*\{0,}\h\w*\%(\[\%(\d\+\|\h\w*\)]\)\{0,}\%(->\|\.\)\=\)\+\s*[-+*/^|%]\==
928 cpp ^\(\s*\h\w*\(\[\d\+]\)\{0,}\(->\|\.\)\=\)\+\s*[-+*/^|%]\==
932 matlab \%(^.*=\)\&\%(^\s*\%(\%(if\>\|elseif\>\|while\>\|for\>\)\@!.\)*$
933 tex ^\([^&]*&\)\+[^&]*\\\{2
936 AutoAlign looks backwards from the current line, searching for the first
937 preceding line _not_ containing the pattern. It uses b:autoalign_notpat1,
938 b:autoalign_notpat2, etc for this. If the "not pattern" has moved since
939 the mark ('a) was made, AutoAlign will start aligning from the current
943 ==============================================================================
944 4. AutoAlign Internals *autoalign-internals*
946 AutoAlign is triggered to operate during insert mode when a special
947 character (such as "=") is encountered using an inoremap. Each ftplugin
948 specifies its own triggers. The inoremap turns virtualedit off, calls
949 AutoAlign(), and then deletes the trigger character (which may have or may
950 not have moved) and then inserts it to keep the operation otherwise
953 AutoAlign attempts to perform its automatic alignment on an "AutoAlign
954 region". Alignment, of course, is performed over that region. The idea
955 is to start an AutoAlign region upon receipt of a trigger character and
956 a matching required pattern; subsequently, alignment is done over the
957 AutoAlign region is active and whenever the region has more than one line
960 Such a region begins with the presence of a required pattern. That first
961 line is also marked with mark-a ('a). If the mark 'a is moved, then the
962 AutoAlign region is terminated. There are several ways that an AutoAlign
963 region is terminated; see below.
965 Associated with each trigger character are three or four patterns. Also,
966 each trigger character inoremap is to have an associated count, referred
970 < This pattern is required for AutoAlign to consider that an AutoAlign
971 region has started. If a positive # is passed to AutoAlign(), then
972 the required pattern is needed to allow the AutoAlign region to
973 continue whenever a trigger character is encountered. A negative #, a
974 trigger character, and a failed match to b:autoalign_reqdpat# will
975 terminate the AutoAlign region.
978 < This pattern must match just before the AutoAlign region starts. It
979 is used to search before the current line. If the non-pattern
980 matching line is not the same as it was when the AutoAlign region
981 began, then the AutoAlign region is terminated.
984 < This pattern is optional; if it matches, the AutoAlign region is
985 terminated. The fplugin/html/AutoAlign.vim script uses </table>,
986 for example, to terminate table aligning.
989 < This is the command used to invoke alignment on the AutoAlign region.
992 < This variable holds the trigger character.
994 Of course, the :AA command is also available to turn AutoAlign off.
997 ==============================================================================
998 5. AutoAlign History *autoalign-history*
1000 13 : Oct 19, 2006 : ftplugin/cpp/AutoAlign.vim fixed for < and >.
1001 Introduced b:autoalign_trigger# so AutoAlign
1002 can put cursor back where it belongs.
1003 * AutoAlign now pluginkiller immune
1004 Mar 26, 2007 * AutoAlign's invocation of Align sometimes caused
1005 the cursor to jump to the first line rather than
1006 the current line (ex: for Maple's :=). Fixed.
1007 Aug 15, 2007 * Changed the imaps's right-hand-side to use,
1008 typically, =<c-r>=AutoAlign(#) instead of
1009 =<c-o>:silent call AutoAlign(#).
1010 Thanks to Antony Scriven! Gets that "|.|"
1012 12 : Sep 19, 2006 : ftplugin/bib/AutoAlign.vim fixed
1013 11 : Mar 23, 2006 : v10 had debugging enabled; this one has debugging
1015 * now decides to use startinsert vs startinsert!
1016 before the alignment by using the "atend" variable,
1017 which holds the result of testing whether the cursor
1018 is at the end-of-line or not.
1019 10 : Mar 16, 2006 : using startinsert! to recommence editing
1020 AutoAlign only triggered when the trigger character
1021 is at the end of the current line being inserted.
1022 * works with ve=all and ve= (see |'ve'|)
1023 9 : Mar 16, 2006 : seems to have stopped working with virtualedit off.
1024 Now works with virtualedit off or on. If vim 7.0
1025 is in use, AutoAlign doesn't use SaveWinPosn()
1026 or RestoreWinPosn(), so it may work faster.
1027 8 : Jan 18, 2006 : cecutil updated to use keepjumps
1028 * plugin/AutoAlign.vim was missing from distribution
1029 7 : Mar 31, 2005 : supports html
1030 * b:autoalign_suspend# for suspend-alignment pattern
1031 implemented, along with using AutoAlign(-#) to avoid
1032 having a reqdpat failure doing an AutoAlign suspension.
1033 The absolute value of # is used to refer to
1034 b:autoalign_reqdpat#, b:autoalign_notpat#, and
1035 b:autoalign_suspend#.
1036 Apr 22, 2005 * sanity check included to prevent an attempt to access
1037 an undefined variable (b:autoalign_reqdpat{i})
1038 6 : Mar 30, 2005 : AutoAlign is split into a plugin containing the
1039 majority of vimscript; the supported ftplugins
1040 contain the invoking imaps and pattern definitions
1041 that the plugin uses.
1042 5 : Jan 24, 2005 : first release of AutoAlign using vim's user-help.
1043 * using g:mapleader instead of a built-in backslash to
1045 * map and function changed to allow use of "." to
1046 repeat entry of =... expressions.
1047 4, Jul 02, 2004 : see |i_ctrl-g_u| -- breaks undo sequence at every align
1048 3, Mar 03, 2004 : autoalign not taken if a no-pattern line is
1049 in-between the keepalign line and the current line
1050 2 : b:autoalign==0: turns autoalign off
1051 b:autoalign==1: turns autoalign back on
1052 * 'a now used during autoalign, and AlignMap's \t=
1053 If user changes 'a, then AutoAlign recognizes that
1054 it is not to keep aligning
1055 * The :AA command can be used to toggle AutoAlign
1058 ==============================================================================
1059 vim:tw=78:ts=8:ft=help