sponsor Vim development Vim logo Vim Book Ad

Easy alignment to column : Quickly align a word to a predefined column

 script karma  Rating 7/4, Downloaded by 1201  Comments, bugs, improvements  Vim wiki

created by
Niels Aan de Brugh
 
script type
utility
 
description
This script was made to ease typing programming code like:

    int                        someVariable;
    double                     foo;
    std::vector< std::string > andSomeLongerName;

(If this doesn't look nicely aligned it's because you're not viewing it using a fixed-width font.)

The attached script allows you to quickly align the variable names on the same (virtual) column. It defines two mappings for this:

  ,a : Align the current cursor to the predefined column.
  ,A : Try to find the alignment column automatically on the previous line.

(Replace , with your g:mapleader.)

The first mapping actually does want we want to achieve, but the latter makes it really easy to use. It looks for the separating gap, which is \s\s (two consecutive white-space characters), and a single tab (following by anything) as a plan B. This may not always work of course. To specify the column, I hijack one of your mark (c in this case), which you can always set manually. If you don't want mark c to be sacrificed to the script, it's very easy to adapt it and make it use another (by editing the key mappings in the file).

The variable g:align_uses_tabs can be reset if you want the script to only insert spaces. Else, it inserts as many tabs as possible, than "fine-tunes" using spaces.
 
install details
 

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
alignment.vim 0.2.1 2007-09-13 6.0 Niels Aan de Brugh Added key mapping for align (,a) and using Unix EOLs now (thanks to Maarten Bressers for noticing).
alignment.vim 0.2 2007-08-29 6.0 Niels Aan de Brugh Fix for expandtab.
Align at white-space at the beginning of a line too.
alignment.vim 0.1 2007-08-03 6.0 Niels Aan de Brugh Initial upload
ip used for rating: 3.145.163.58

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 the maillist. Help Bram help Uganda.
   
Vim at Github