Skip to content

Commit

Permalink
Allow for easier align rules
Browse files Browse the repository at this point in the history
Now you can use the glob char '*' when defining how to align columns.
Use `:let b:csv_arange_align='l*'` to have all columns left aligned.

closes #99
  • Loading branch information
chrisbra committed Nov 30, 2016
1 parent 2cc7cd2 commit cceabea
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
https://github.com/chrisbra/csv.vim/issues/84, thanks!)
- Do not remove tabs on `:UnArrangeColumn` (reported by taylor-peterson in
https://github.com/chrisbra/csv.vim/issues/98, thanks!)
- Allow for better aligning of columns (reported by taylor-peterson in
https://github.com/chrisbra/csv.vim/issues/99, thanks!)

## 0.31 Jan 15, 2015
- supports for Vim 7.3 dropped
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,12 @@ overriden by setting the "b:csv_arrange_use_all_rows" variable (see below).

If [range] is not given, it defaults to the current line.

By default, the columns will be righ-aligned. If you want a different
By default, the columns will be right-aligned. If you want a different
alignment you need to specify this through the b:csv_arrange_align variable.
This is a string of flags ('r': right align, 'l': left align, 'c': center
alignment, '.': decimal alignment) where each flag defines the alignment for
a particular column (starting from left). Missing columns will be right aligned.
You can use '\*' to repeat the previous value until the end.
So this:

```vim
Expand All @@ -246,6 +247,13 @@ Will left-align the first column, center align the second column, decimal
align the third column and all following columns right align. (Note: decimal
aligning might slow down Vim and additionally, if the value is no decimal
number it will be right aligned).
And this:

```vim
:let b:csv_arrange_align = 'l*'
```
will left align all columns.

If you change the alignment parameter, you need to use the "!" attribute, the
next time you run the `:ArrangeCol` command, otherwise for performance
reasons, it won't be considered.
Expand Down
10 changes: 9 additions & 1 deletion doc/ft-csv.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,13 @@ overriden by setting the "b:csv_arrange_use_all_rows" variable (see below).

If [range] is not given, it defaults to the current line.

By default, the columns will be righ-aligned. If you want a different
*csv_arrange_align*
By default, the columns will be right-aligned. If you want a different
alignment you need to specify this through the b:csv_arrange_align variable.
This is a string of flags ('r': right align, 'l': left align, 'c': center
alignment, '.': decimal alignment) where each flag defines the alignment for
a particular column (starting from left). Missing columns will be right aligned.
You can use '*' to repeat the previous value until the end.
So this: >

:let b:csv_arrange_align = 'lc.'
Expand All @@ -244,6 +246,12 @@ Will left-align the first column, center align the second column, decimal
align the third column and all following columns right align. (Note: decimal
aligning might slow down Vim and additionally, if the value is no decimal
number it will be right aligned).
And this: >

:let b:csv_arrange_align = 'l*'

Will left align all columns.

If you change the alignment parameter, you need to use the "!" attribute, the
next time you run the |:ArrangeCol| command, otherwise for performance
reasons, it won't be considered.
Expand Down
7 changes: 6 additions & 1 deletion ftplugin/csv.vim
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,12 @@ fu! <sid>Columnize(field) "{{{3
let width = get(b:col_width, colnr, 20)
let align = 'r'
if exists('b:csv_arrange_align')
let align_list=split(get(b:, 'csv_arrange_align', " "), '\zs')
let align=b:csv_arrange_align
let indx=match(align, '\*')
if indx > 0
let align = align[0:(indx-1)]. repeat(align[indx-1], len(b:col_width)-indx)
endif
let align_list=split(align, '\zs')
try
let align = align_list[colnr]
catch
Expand Down

0 comments on commit cceabea

Please sign in to comment.