Align - Provides commands and maps to help produce aligned text, eqns, declarations, etc : vim online
Keywords: Vim, Vi IMproved, text editor, home, documentation, tips, scripts, news

Align : Provides commands and maps to help produce aligned text, eqns, declarations, etc
script karma | Rating 528/165, Downloaded by 4114
created by
Charles Campbell
script type
utility
description
Align and AlignMaps lets you align statements on their equal signs, make comment boxes, align comments, align declarations, etc. There are two basic commands provided by this package: AlignCtrl options sep1 sep2 sep3 ... [range]Align sep1 sep2 sep3 ... The "sep#" are regular expressions which describe separators that delineate fields; Align will line up the separators. The range may be any Vim range, _including_ visual-blocks. Align works on lines of the form: (ws==whitespace) ws-field-ws-sep-ws-field-ws-sep-ws-field-... ws-field-ws-sep-ws-field-ws-sep-ws-field-... Note that white-space (ws) surrounding separators is ignored. There are several options to help with deciding what to do with initial white space. By default Align re-uses the first line's initial white space, but one may use AlignCtrl to retain or remove each line's initial white space. Align handles alignment on multiple separators, not just the first one, and the separators may be the same across the line or different. The <Align.vim> and <AlignMaps.vim> files are plugins and require vim 6.1 or higher. EXAMPLES: :5,10Align = Align on '=' signs :'<,'>Align = + - \* / Align on any of the five separator characters shown. Note that visual block mode was used to fire off Align. :AlignCtrl =lp1P1I which means: = all separators are equivalent l fields will be left-justified p1 pad one space before each separator P1 pad one space after each separator I preserve and apply the first line's leading white space to all Align'd lines :help align Gives help for Align ALIGNMENT CONTROL Alignment control allows for left or right justification or centering of fields, cyclic (sequentially active) or equivalent (simultaneously active) regular expressions to specify field separators, initial white space control, optional visual-block use (ie. apply Alignment only within a block), user-specified white-space padding about separators, and multiple separators. MANY ALIGNMENT MAPS AlignMaps.vim provides a number of maps which make using this package easy. They typically either apply to the range 'a,. (from mark a to current line) or use the visual-selection (V, v, or ctrl-v selected): \t= : align assignments (don't count logic, like == or !=) \t, : align on commas \t| : align on vertical bars (|) \tsp : align on whitespace \tt : align LaTeX tabular tables AlignMaps also provides some internally complex maps for aligning C declarations, Ansi C function arguments, html tables, LaTeX tabulars, and trailing comments: \acom : align comments \adec : align C declarations (one variable per line) \afnc : align ansi-style C function input arguments \Htd : align html tables To see some examples of this, check out http://mysite.verizon.net/astronaut/vim/textab.html#Examples (the proportional fonts used by most browsers in showing you this page preclude showing the examples here). The help for Align and AlignCtrl also contains many examples. ALIGNMENT ON VISUAL BLOCKS AND g,v-LIKE CONTROL Sometimes one wants to align only a subset of text in a range, based on patterns or column extents. Align supports both types of restrictions! Visual-block selection may be used to restrict Align to operate only within that visual block. AlignCtrl supports "g" and "v" patterns that restrict Align to operate on lines which match (or don't match, respectively) those patterns. NEW STUFF: There's a number of new AlignCtrl options: - allows one to skip a separator (treat it as part of a field) + repeat the last lrc justification (ex. lr+ == lrrrrrr... ) : treat the rest of the line as a field; acts as a modifier to the last lrc. < left-justify the separator > right-justify the separator | center the separator These are, except for the ":", cyclic parameters. In other words, >< is equivalent to ><><><><... . Thus separators can be of differing lengths (ex. -\+ as a separator pattern can match -, --, ---, etc and the separators will be left/right/center justified as you wish). To get some automatic aligning of = in the C and vimL languages, check out script#884 for two ftplugins (which use Align). Alternative Aligners: Gergely Kontra's vimscript#176 Johannes Zellner's http://www.zellner.org/vim/autoload/ Mohsin Ahmed's vimtip#570 Thank you for rating Align! --------------------------------------- DISCUSSION and COMMENTS: --------------------------------------- Use vimtip#139 for discussion and comments. Please use email for bugs. Enjoy!
install details
1. Put <Align.tar.gz> in your .vim or _vimfiles directory. 2. gunzip Align.tar.gz 3. tar -oxvf Align.tar Result: plugin/Align.vim plugin/AlignMaps.vim doc/Align.txt 4. Fire up vim or gvim, then :helptags ..path../.vim/doc -or- : helptags ..path\_vimfiles\doc 5. Align needs vim v6.1 or later
rate this script | Life Changing Helpful Unfulfilling
script versions (upload new version) Click on the package to download.
package | script version | date | Vim version | user | release notes
--- | --- | --- | --- | --- | ---
Align.tar.gz | 27/31 | 2005-04-15 | 6.0 | Charles Campbell | Align: GetLatestVimScripts/AutoInstall supported AlignMaps: new map: \\adcom (align declaration-style comments), \\a, now wors across multiple lines with different types, cecutil.vim now used, more number alignment maps (\\aenum, \\aunum)

| If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly. Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda. |  |